1

I have a data table called dtchild and it contains a column named FILE_CONTENT. In my data table, FILE_CONTENT data is stored as a byte[] array.

How to retrieve FILE_CONTENT data from the data table and convert it into an image?

Mario Petrovic
  • 5,868
  • 12
  • 32
  • 54

3 Answers3

0

// bytes is the byte[] array of your file content :

using(MemoryStream ms = new MemoryStream(bytes))
{
    var Image = Image.FromStream(ms);
}
Khalil Lazhar
  • 391
  • 1
  • 12
0

Considering you want to show image in asp.net web forms

Try this code , on aspx page :

     <img id='yourID' runat='server'/>

On CS page


      byte[] Binary = (byte[])(dt.Rows[0]["Your column"]);
      string base64string= Convert.ToBase64String(Binary, 0, Binary.Length);
      yourID.Src = "data:image/jpg;base64," + base64String;
Khalil Lazhar
  • 391
  • 1
  • 12
Atk
  • 754
  • 1
  • 4
  • 12
0
byte[] imgData = (byte[])dt.Rows[0]["Photo"];
MemoryStream ms = new MemoryStream(imgData);
Image img = Image.FromStream(ms);
pictureBox1.Image = img;
Shaido
  • 25,575
  • 21
  • 68
  • 72
Saleem Kalro
  • 978
  • 8
  • 12