Image Resizing & Cropping on the fly in .NET - high quality
While developing a CMS for small gallery websites, I decided to store only the original uploaded image and not to create a thumbnail upon uploading. I didn't want, of course, to use the html resizing feature, especially not while uploading high res images. Instead, I created a generic handler that creates the thumbnail image on the fly. Not only this handler knows how to resize the image, but also to crop it, in case I want all the images to be on a fixed ratio of width and height. So, how is it done? There are many blog posts of resizing images on the fly. where you'll find a code similar to this: public static Bitmap CreateThumbnail(Bitmap loBMP, int lnWidth, int lnHeight) { System.Drawing.Bitmap bmpOut = null; try { ImageFormat loFormat = loBMP.RawFormat; decimal lnRatio; int lnNewWidth = 0; int lnNewHeight = 0; //*** If the image is sm...