On Thu, Mar 4, 2010 at 6:39 AM, Greg Keogh <g...@mira.net> wrote:

>   >Implement your own IHttpHandler, and write the image directly to the
> Response Stream. Implement your caching if needs be.
>
> I just found a Scott Hanselman 
> page<http://www.hanselman.com/blog/ASPNETFuturesGeneratingDynamicImagesWithHttpHandlersGetsEasier.aspx>where
>  does this, turning text into images. It makes sense and I could
> pervert it to take a byte[] as data I suppose, but I was really hoping for
> an easier solution ... one where I don’t have to write code or even think at
> all ;-)
>
As David Kean said, if your byte[] array in SQL is a pure GIF, JPEG, PNG,
etc. then just read the into a Stream and squirt it out to the browser as
the correct image type.  Coding a .ashx should be pretty straight forward.
You would then reference the image as <img src="yourImageFetcher.ashx" />

yourImageFetcher.ashx would query the database, take the column with the
byte[] array and return that as a stream to
httpContext.Response.OutputStream.  The handler must add
httpContext.Response.ContentType = "image/<whatever>";

If you want to manipulate the image, you need a server-side "safe" way to do
it.  IIRC, Hanselman uses System.Drawing - the MSDN
documentation<http://msdn.microsoft.com/en-us/library/system.drawing.aspx>suggests
you DO NOT use System.Drawing in services and ASP.Net.  I just went
through this when helping a client.  I don't think it's as bad as using,
say, Office applications on the server - but you takes your chances on
stability.  Look for a lightweight thread-safe image processing library
perhaps.

> Greg
>
-- 
Richard Carde

Reply via email to