Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

tool to convert images to base64

any tools available that I can download to my windows machine that I can use to convert images to base 64 images? I am working with visual studio 2010 and tried this plugin but I cant get it working (dont get the option to get base 64 of image) unfortunately as I really like the way its suppose to work.

I would prefer something locally than uploading to a website and letting them convert the images.

like image 999
amateur Avatar asked Jul 16 '11 22:07

amateur


1 Answers

If you have Visual Studio why not toss together a quick app which 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;
}
like image 72
Aaron McIver Avatar answered Sep 30 '22 14:09

Aaron McIver