Tuesday, March 4, 2008

Custom Image Control

While creating a custom document reader for the historical document project, I required an image control which will allow conversion of tiff files to jpeg. The default .NET image control does not render tiff images, and will only allow output directly from an ImageURL property. This restriction limits a simple interface for the image control when image manipulation is necessary before rendering, or when embedding the image control in a data bound list type control.

With inspiration from this control designer, Peter Bromberg, I have re-written his custom image control in visual basic and added inheritance directly from the asp:image control. The custom control has a bitmap property set at run time, outputting a Jpeg image directly to the control. As noted, this additional functionality enables the image control to receive an image directly from a data bound list control, and allows any sort of server side image conversion before rendering.

Here are the two classes used to compile the new control (ImageControl, ImageHandler). At runtime, any GDI+ image conversion is done on the server, then the image is set to the bitmap property of the control.

While progressing with this project, I hope to encapsulate this custom control inside of a Visual Studio 2008 ListView control, which is bound to a database or XML datasource. This will eventually make a document viewer for historical documents.

As Scott Guthrie says, "Happy Coding!"

No comments: