1 out of 1 rated this helpful - Rate this topic

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.

The following example constructs an Image object from a JPG file. 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.

Thumbnail Image
Note Note

In this example, a callback method is declared, but never used. This supports all versions of GDI+.

	public bool ThumbnailCallback() {
            return true;
        }

        private void GetThumbnail(PaintEventArgs e)
        {

            Image.GetThumbnailImageAbort callback = 
                new Image.GetThumbnailImageAbort(ThumbnailCallback);
            Image image = new Bitmap(@"c:\FakePhoto.jpg");
            Image pThumbnail = image.GetThumbnailImage(100, 100, callback, new
               IntPtr());
            e.Graphics.DrawImage(
               pThumbnail,
               10,
               10,
               pThumbnail.Width,
               pThumbnail.Height);
        }
      

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

  1. Create a new Windows Forms application.

  2. Add the example code to the form.

  3. Create a handler for the form's Paint event

  4. In the Paint handler, call the GetThumbnail method and pass e for PaintEventArgs.

  5. Find an image file that you want to make a thumbnail of.

  6. In the GetThumbnail method, specify the path and file name to your image.

  7. Press F5 to run the example.

    A 100 by 100 thumbnail image appears on the form.

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.