Dynamic Images

Published 07 January 04 07:03 PM | despos

First post of the new year!

An interesting ASP.NET 2.0 solution that can easily be back-propagated to ASP.NET 1.x is the DynamicImage control which in Whidbey partners the familiar Image control. I don't really know how many people really used the <asp:Image> control over the static and more efficient <img src=""> or at least the <img runat=server> tag. However, the Image control doesn't help a little to create more neatly and elegantly code that retrieves image bytes from a database.

DynamicImage does it, and very well, through a built-in HTTP handler named cachedimageservice.axd. The control gets the data and makes a copy to the ASP.NET cache using a GUID as the key. Next, when it comes to generating the markup, the <img> tag is made point to handler with a data parameter that references the GUID.

Why HTTP handlers? Because a HTTP handler is more efficient (lightweight, exactly) than a page. And this is a good advice also for ASP.NET 1.x if you play with dynamic images.

DynamicImage can get images in four ways--GDI+ objects, URLs, array of bytes, ASP.NET 2.0 generators. Do not use plain URLs with this control (the related property is ImageFile). Use the Image control instead which exploits the IIS capability of quick serving image files. The ImageFile property is only useful if you write dual apps, desktop and mobile. In this case, the DynamicImage control offers extra service like automatic adaptation of type and size to the browser's caps.

Really cool stuff!

 

Comments

# Kevin Daly said on January 7, 2004 01:41 PM:

I've been experimenting with this one myself over the last few days (and .ASIX files as well). Truly very cool.
One thing though - for generated images I've been resorting to using .png as the output format because for .jpeg the image quality is pretty horrible...after some experimentation I've come to the conclusion that the limitation is at the DynamicImage end rather than the ImageGenerator end.
There must be something I can do here that I'm missing...any idea how to control the quality of a generated image from the DynamicImage control? (the observed effect is very bad colour bleeding and ghosting - unfortunately all the published examples I've seen use a black background, which coincidentally hides the problem to some extent).
I'd be very grateful to know if there's a known way to fix this.

# DinoE said on January 12, 2004 04:13 AM:

See next post

# TrackBack said on January 19, 2004 09:57 PM:

Leave a Comment

(required) 
(required) 
(optional)
(required)