Dynamic Image Scaling

In a recent ASP.Net project, I needed to display images within a specific height and width boundary. Those that have worked with image resizing know that to keep the image looking the way it is supposed to, it has to be scaled. In that I mean the height and width must be changed in the correct amounts to prevent skewing the image and causing it to not look right. Scaling images one at a time is very time consuming and not practical. This is also a problem when the images are supplied by users and there is little to no control over the image sizes.

One way to address this problem is to use an image handler to dynamically scale the image and return it for display in the image control. This is accomplished by using an ASHX file and passing the needed information to locate the image and what height and width to scale it to. An ASHX file is a special ASP.Net file that executes code but does not have a GUI display. So it is like an ASPX file without the GUI, just the codebehind.

You can see a sample of this solution here.

The source code can be downloaded here. The main file to reuse in other projects is image.ashx. Feel free to use it as is or to make your own modifications.

Please comment on any improvements and changes you make so everyone can benefit from them.

This entry was posted in Software / Coding and tagged , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*


* four = 36

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>