Q:

How to display images in MemoryStream? 

I have some images (png's and jpg's mostly) that I'm storing in SQL Server 2008's FileStream.  I am able to retrieve said images and store them in a MemoryStream.  
I have a certain webpage that I need to display the image on that is within the MemoryStream.  Is there some way that I can go about displaying the contents of the MemoryStream within an HTML image tag (or even better, within an ASP.NET Image control)? 

A:

yes, 

point the image source to a ashx handler
have the handler query the image from the database
write the bytes to the response stream and set the content type

html
<img src="loadimage.ashx?id=..."/>

add a generic handler to your project and loadimage
handler
class loadimage: ihttphandler
{
   public void Process(HttpContext context)
   {

        var id = context. Request["id"];
        var row = GetImageFromDb(id);

        var response = context. Response;
        response. AddHeader("content-disposition", "attachment; filename=" + row["anem of image"]);
        response. ContentType = row["mime type"].ToString(); //png or gif etc. 
        response. BinaryWrite((byte[])row["image blob"]);
   }

   public bool Reuse { get {return true; } }
}

