Decoding Base64 Image

ⅰ亾dé卋堺 提交于 2019-12-18 12:59:13

问题


I have got a Base64 image in an HTML embedded, how can I decode this using C# or VB.net.


回答1:


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



回答2:


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

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




回答3:


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.




回答4:


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



来源:https://stackoverflow.com/questions/5083336/decoding-base64-image

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