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.
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.