Generate Thumbnails in ASP.NET

I needed to generate Medium (250 X 250) and small (150 X 150) size images from Large (500 X 500) size images as Product images to display in a shopping cart application.

To generate thumbnail images (for scenario I wrote above, or to display iconic Product images within GridView along with Product Details):

System.Drawing.Image imThumbnailImage;
System.Drawing.Image _InputImage = System.Drawing.Image.FromFile(Server.MapPath("large.jpg"));

imThumbnailImage = _InputImage.GetThumbnailImage(100, 100,
new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback), IntPtr.Zero);
imThumbnailImage.Save(Server.MapPath("thumb.jpg"));

imThumbnailImage.Dispose();
_InputImage.Dispose();

public bool ThumbnailCallback() { return false; }

Image.GetThumbnailImage Method (System.Drawing) is used to generate thumbnails.
Parameters to pass in this method are:

thumbWidth (Int32):
The width, in pixels, of the requested thumbnail image.

thumbHeight (Int32):
The height, in pixels, of the requested thumbnail image.

callback (System.Drawing.Image.GetThumbnailImageAbort):
A Image.GetThumbnailImageAbort delegate. In GDI+ version 1.0, the delegate is not used. Even so, you must create a delegate and pass a reference to that delegate in this parameter.

callbackData (System.IntPtr):
Must be Zero.

Contact Form

Name

Email *

Message *

Popular Posts

Life Cycle of a Web Request

Python Keywords

Internal Revenue Service (IRS) - Questions About Your Tax Refunds In US

Role Of Thyroid Gland In Our Body And Its Effects On Weight Loss And Gain

Why do we blow out candles on our birthdays? - A deep insight into it

How to create the FAANG: Resume Template for Software Engineer?