6

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

3
  • 2
    Just out of curiosity - are you sure that your Base64 converted compressed file is actually smaller than the original Jpeg? If I were you. I'd settle for just using POST file request and let the standard Gzip compression do whatever it can. That would save processing power on both the client and the server, and I strongly suspect it will save bandwidth as well. Commented Jan 29, 2013 at 10:17
  • I'm not sure whether Base64 String is smaller or not. please help me out with the best way to compress image, upload the compressed and how to convert the uploaded image to the same image.please don't send me the link, i had already tried all the links.. Commented Jan 29, 2013 at 10:31
  • Umh, I am really confused how someone can "try all the links". That said, the easiest way to upload an image would be stackoverflow.com/a/7163513/17028 (Android client code) and haacked.com/archive/2010/07/16/… (ASP.NET server code, so ignore any html in that post) Commented Jan 29, 2013 at 10:51

1 Answer 1

6

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)
{
  // ...
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.