user1909177
user1909177

Reputation:

decode Base64 byte Array to Image in C#

I am making a small application in android that browse image from the gallery or take a picture from the camera. Then the selected image is compressed and uploaded to the server. I had compressed the image using Base64 String in android and for uploading image i am making a web service in ASP.NET. But i'm not sure how to decode the string(converted using Base64 in android) into image(the web service should be able to convert it). Please help me.

Thanks in advance

Upvotes: 6

Views: 5882

Answers (1)

Adil
Adil

Reputation: 148180

You can convert base64string to image by Image.FromStream. You will need to convert the base64string to stream first.

byte[] imageBytes = Convert.FromBase64String(imgBase64String);
Image img = null;

using (MemoryStream ms1 = new MemoryStream(imageBytes))
{
     img = Image.FromStream(ms1);
}

if (img != null)
{
  // ...
}

Upvotes: 6

Related Questions