views:

795

answers:

3

I wish to create a very simple web app that simply displays an Image(s) from a database based upon either a date (from a calendar click event) or from a keyword search, getting the image(s) is no problem but I don't know how to display the resulting image. Preferably I would like to display the image in a table or grid or whatever, adjacent to the Calendar and TextBox on the same page that I used to get the search critera

So how to I stream an image to a page from a codebehind bitmap variable ?

Edit: The database is a cloud database, so databinding is out.

A: 

This isn't a good idea, since you don't know when to release the resource.

Rather, create a page (or a page handler, etc, etc) which will take the parameters you need in the querystring to perform the lookup in the database to get the image.

Then, in the handler, you load your image from the database and then stream the bytes back through the page.

In the original page, you set the src attribute of the img tag to the other page, with the appropriate parameters.

casperOne
How about sites like "the daily dilbert"? Where they do pretty much exactly what I am trying to achieve.
Tim Jarvis
+2  A: 

Take a look at the DynamicImageHandler for ASP.NET up on the CodePlex ASP.NET Futures site:

http://www.hanselman.com/blog/ASPNETFuturesGeneratingDynamicImagesWithHttpHandlersGetsEasier.aspx

Scott Hanselman
Scott, perfect. Just what I was looking for. Thanks.
Tim Jarvis
A: 

If you don't have the physical file on hand, try using:

Response.OutputStream.Write(bitmapbuffer, bitmapbuffer.Length)

I've done this in the past to dynamically serve pdfs and tifs, and it works quite nicely. You'll need to set your img's src attribute to contain the information you need. This web site has an example close to what you are looking for:

http://www.jigar.net/articles/viewhtmlcontent3.aspx

DavGarcia