0

I tried to convert a byte array to an image but nothing and no error.

byte[] data = user.Properties["thumbnailPhoto"].Value as byte[];
if (data != null)
{
    using (MemoryStream s = new MemoryStream(data))
    {
          Bitmap bmp = new Bitmap(s);
          imbThumbnail.ImageUrl = bmp.ToString();
    }
}
5
  • 3
    That's not how URLs work. You need an HTTP endpoint, or a data: URI. Commented Jan 19, 2014 at 15:12
  • bmp.ToString() (rather, Object.ToString()) does not provide an URL as you seem to believe... Commented Jan 19, 2014 at 15:13
  • 1
    Try imbThumbnail.ImageUrl = "data:image/jpeg;base64,"+ Convert.ToBase64String(data); Commented Jan 19, 2014 at 15:17
  • 1
    What is the type of the object imbThumbnail ? Commented Jan 19, 2014 at 15:18
  • @L.B thanks it worked well , please add your answer to vote your answer Commented Jan 20, 2014 at 7:44

3 Answers 3

1

You don't need Bitmap class. All you need is base64 encoded data as below

imbThumbnail.ImageUrl = "data:image/jpeg;base64,"+ Convert.ToBase64String(data);
Sign up to request clarification or add additional context in comments.

Comments

0

Try this.

public Image byteArrayToImage(byte[] byteArrayIn)
{
     MemoryStream ms = new MemoryStream(byteArrayIn);
     Image returnImage = Image.FromStream(ms);
     return returnImage;
}

Source : C# Image to Byte Array and Byte Array to Image Converter Class

Comments

0

Try this code:

var stream = new MemoryStream(bytes);
var image = Image.FromStream(stream);

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.