How to display image blob from database?

Discussion in 'ASP .Net' started by Olav Tollefsen, Apr 25, 2004.

  1. 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
    Olav Tollefsen, Apr 25, 2004
    #1
    1. Advertising

  2. Olav Tollefsen

    Rick Spiewak Guest

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

    "Olav Tollefsen" <> wrote in message
    news:...
    > 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
    >
    >
    Rick Spiewak, Apr 25, 2004
    #2
    1. Advertising

  3. 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
    =?Utf-8?B?QmlsbCBCb3Jn?=, Apr 25, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    1
    Views:
    1,250
    Metalore
    Oct 18, 2006
  2. Replies:
    1
    Views:
    623
    =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
    Sep 16, 2007
  3. gsauns
    Replies:
    1
    Views:
    631
    gsauns
    Feb 25, 2008
  4. André Despont

    How can i display blob into GridView

    André Despont, Dec 21, 2006, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    941
    André Despont
    Dec 21, 2006
  5. Replies:
    1
    Views:
    216
Loading...

Share This Page