Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert a Base64 PNG image string to PNG Format in C# [duplicate]

Tags:

c#

c#-4.0

Possible Duplicate:
converting a base 64 string to an image and saving it

I have a PNG image encoded as a Base64 string. I need to convert this string into PNG format. How can I convert this in C#?

like image 820
Imran Qadir Baksh - Baloch Avatar asked Jul 13 '12 04:07

Imran Qadir Baksh - Baloch


1 Answers

using Convert=System.Convert;
using MemoryStream=System.IO.MemoryStream;
using Image=System.Drawing.Image;
//...

byte[] data = Convert.FromBase64String(base64String);
using(var stream = new MemoryStream(data, 0, data.Length))
{
  Image image = Image.FromStream(stream);
  //TODO: do something with image
}
like image 70
Peter Ritchie Avatar answered Sep 22 '22 14:09

Peter Ritchie