How to read binary column in database into image on asp.net page?

Posted by marko on Stack Overflow See other posts from Stack Overflow or by marko
Published on 2010-03-11T21:03:21Z Indexed on 2010/03/11 21:09 UTC
Read the original article Hit count: 189

Filed under:
|

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?

© Stack Overflow or respective owner

Related posts about c#

Related posts about ASP.NET