解码Base64图像

我在嵌入式HTML中有一个Base64图像,如何使用C#或VB.net对其进行解码。

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

使用Convert.FromBase64String获取表示图像二进制的byte[]

然后,您可以将生成的byte[]保存到文件中。

将嵌入的图像刮成字符串。 使用WebClient可能是您最好的选择。 使用Convert.FromBase64String()将base64字符串转换为字节数组。 使用MemoryStreamImage.FromStream()重新构建图像对象。

在上面的示例中,内存流尚未处理。这可能会导致内存泄漏。所以基本的想法是转换为base64string到bytearray []到图像或位图图像创建可以通过内存流完成一个完美的例子给你试试这个链接http:// www .dailycoding.com /post/ convert_image_to_base64_string_and_base64_string_to_image.aspx