How to: Create Thumbnail Images

A thumbnail image is a small version of an image. You can create a thumbnail image by calling the GetThumbnailImage method of an Image object.

Example

The following example constructs an Image object from the file Compass.bmp. The original image has a width of 640 pixels and a height of 479 pixels. The code creates a thumbnail image that has a width of 100 pixels and a height of 100 pixels.

The following illustration shows the thumbnail image.

Dim image As New Bitmap("Compass.bmp")
Dim pThumbnail As Image = image.GetThumbnailImage(100, 100, Nothing, _
   New IntPtr())
e.Graphics.DrawImage( _
   pThumbnail, _
   10, _
   10, _
   pThumbnail.Width, _
   pThumbnail.Height)
Image image = new Bitmap("Compass.bmp");
Image pThumbnail = image.GetThumbnailImage(100, 100, null, new
   IntPtr());
e.Graphics.DrawImage(
   pThumbnail,
   10,
   10,
   pThumbnail.Width,
   pThumbnail.Height);

Compiling the Code

The preceding example is designed for use with Windows Forms, and it requires PaintEventArgs e, which is a parameter of the Paint event handler.

See Also

Other Resources

Images, Bitmaps, and Metafiles
Working with Images, Bitmaps, Icons, and Metafiles