How to read binary column in database into image on asp.net page?
- by marko
I want to read from database where I've stored a image in binary field and display a image.
while (reader.Read())
{
byte[] imgarr = (byte[])reader["file"];
Stream s = new MemoryStream(imgarr);
System.Drawing.Image image = System.Drawing.Image.FromStream(s);
Graphics g = Graphics.FromImage(image);
g.DrawImage(image, new Point(400, 10));
image.Save(Response.OutputStream, ImageFormat.Jpeg);
g.Dispose();
image.Dispose();
}
con.Close();
This piece of code doesn't work:
System.Drawing.Image image = System.Drawing.Image.FromStream(s);
What am I doing wrong?