Decoding Base64 Image

心不动则不痛 提交于 2019-11-30 08:37:15
servermanfail

google.com > base64 image decode c# > http://www.eggheadcafe.com/community/aspnet/2/39033/convert-base64-string-to-image.aspx

Byte[] bitmapData = Convert.FromBase64String(FixBase64ForImage(ImageText));
System.IO.MemoryStream streamBitmap = new System.IO.MemoryStream(bitmapData);
Bitmap bitImage = new Bitmap((Bitmap)Image.FromStream(streamBitmap));

public string FixBase64ForImage(string Image) { 
    System.Text.StringBuilder sbText = new System.Text.StringBuilder(Image,Image.Length);
    sbText.Replace("\r\n", String.Empty); sbText.Replace(" ", String.Empty); 
    return sbText.ToString(); 
}

Use Convert.FromBase64String to get a byte[] representing the image binary.

You can then save the resulting byte[] into a file.

Scrape the embedded image into a string. Using WebClient is probably your best bet. Convert the base64 string to a byte array using Convert.FromBase64String(). Use a MemoryStream and Image.FromStream() to reconstitute an image object.

In above example memory stream has not been disposing This may cause memory leak.So Basic Idea is convertion to base64string to bytearray[] to image or bitmap Image creation can be done through memorystream A perfect example for you Try this link http://www.dailycoding.com/Posts/convert_image_to_base64_string_and_base64_string_to_image.aspx

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!