2

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
  • 7,500
  • 14
  • 42
  • 62

3 Answers3

0

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

using(MemoryStream ms = new MemoryStream(bytes))
{
    var Image = Image.FromStream(ms);
}
KHL
  • 455
  • 2
  • 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;
KHL
  • 455
  • 2
  • 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
  • 27,497
  • 23
  • 70
  • 73
Saleem Kalro
  • 1,046
  • 9
  • 12