How to display image blob from database?

  • Thread starter Thread starter Olav Tollefsen
  • Start date Start date
O

Olav Tollefsen

How can I display photo images stored in a SQL Server 2000 databases in a
DataList or DataGrid without having to write the images to files first?

Olav
 
You should be able to stream them by setting the right mime type in your
output.
 
Olav

You need a url that returns the image you want, which you bind to each listitem in your datagrid/datalist, e.g. <img src='<%# "GetImage.aspx?src=" + ID %>'

In this example, GetImage.aspx uses the ID you pass and does the i/o to get a byte array from the blob, then returns it in the output stream as a picture, e.g
response.ContentType = "image/jpeg"
response.BinaryWrite(MyByteArray

The other nice thing about using GetImage is that you can very simply modify the image before you return it to the stream, such as add a description or copyright notice onto the picture, return a thumbnail, etc. In that case, you'd create your bitmap from the blob, modify it however, then do bitmap.Save(Response.OutputStream, Imaging.ImageFormat.Jpeg) to output it to the stream

For a great discussion of this and a lot more, check out Esposito's Programming Microsoft ASP.NET from MS Press (pp. 1036-1044)

hth

Bil

----- Olav Tollefsen wrote: ----

How can I display photo images stored in a SQL Server 2000 databases in
DataList or DataGrid without having to write the images to files first

Ola
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top