Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Decoding Base64 Image

Tags:

c#

base64

decode

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

like image 428
Ploetzeneder Avatar asked Feb 22 '11 20:02

Ploetzeneder


2 Answers

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(); 
}
like image 135
servermanfail Avatar answered Oct 03 '22 07:10

servermanfail


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

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

like image 45
Oded Avatar answered Oct 03 '22 06:10

Oded