开发者

tool to convert images to base64

开发者 https://www.devze.com 2023-03-21 06:18 出处:网络
any tools available that I can download to my windows machine tha开发者_开发技巧t I can use to convert images to base 64 images? I am working with visual studio 2010 and tried this plugin but I cant g

any tools available that I can download to my windows machine tha开发者_开发技巧t 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.


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;
}


I know it's an old question, I suggest CodVerter: https://codverter.com/src/imagetobase64
Looks like it would be an easy fix for your issue.

0

精彩评论

暂无评论...
验证码 换一张
取 消