2011-07-16 5 views
3

기본 64 이미지로 이미지를 변환하는 데 사용할 수있는 내 Windows 컴퓨터에 다운로드 할 수있는 모든 도구를 사용할 수 있습니까? 나는 Visual Studio 2010을 가지고 일하고 있는데 this plugin을 시도했지만 불행하게도 실제로 작동하는 방식을 좋아하기 때문에 작동하지 않습니다 (이미지의 기본 64 개를 얻지 못합니다).base64로 이미지를 변환하는 도구

나는 웹 사이트에 업로드하고 이미지를 변환시키는 것보다 로컬에서 뭔가를 선호합니다.

답변

3

Visual Studio를 사용하는 경우 왜 can do this for you이라는 빠른 응용 프로그램을 함께 사용하지 않으시겠습니까?

public string ImageToBase64(Image image, System.Drawing.Imaging.ImageFormat format) 
{ 
    using (MemoryStream ms = new MemoryStream()) 
    { 
    // Convert Image to byte[] 
    image.Save(ms, format); 
    byte[] imageBytes = ms.ToArray(); 

    // Convert byte[] to Base64 String 
    string base64String = Convert.ToBase64String(imageBytes); 
    return base64String; 
    } 
} 

public Image Base64ToImage(string base64String) 
{ 
    // Convert Base64 String to byte[] 
    byte[] imageBytes = Convert.FromBase64String(base64String); 
    MemoryStream ms = new MemoryStream(imageBytes, 0, 
    imageBytes.Length); 

    // Convert byte[] to Image 
    ms.Write(imageBytes, 0, imageBytes.Length); 
    Image image = Image.FromStream(ms, true); 
    return image; 
} 
관련 문제