Creating Thumbnail Images
You can use a similar technique to create a true thumbnail of your image. The Image class supports a
GetThumbnailImage method which generates thumbnails. For example:
const string cstrThumbFileName =
"\\Thumb_Sample.gif";
System.Drawing.Image img =
System.Drawing.Image.FromFile
(strFileName);
System.Drawing.Image.GetThumbnailImageAbort
imgCallBack = new
System.Drawing.Image.GetThumbnailImageAbort
(CallBackMethod);
System.Drawing.Image imgThumbnail =
img.GetThumbnailImage(img.Width/4,
img.Height/4, imgCallBack, IntPtr.Zero);
imgThumbnail.Save
(Application.StartupPath +
cstrThumbFileName);
Calling the
GetThumbnailImage method and passing in the width and height of the thumbnail, along with an
Image.GetThumbnailImageAbort delegate and
IntPtr.Zero creates a new instance of the Image object that represents the thumbnail of your original image.
| Author Note: The Image.GetThumbnailImageAbort delegate and IntPtr.Zero parameters are required even though they support a callback that is not yet used in GDI+ 1.0. |