Files
docs-desktop/dotnet-desktop-guide/framework/winforms/advanced/how-to-create-thumbnail-images.md
T
Andy De George c0ba284473 Initial winforms content migrated (#18)
* Merge winforms framework content to working branch (#14)

* Breadcrumb / TOC / Move net5 to net folder (#15)

* change path from net5 to net

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Add .net 5 winforms placeholder article (#16)

* added some metadata and adjusted net5 placeholder

* corrections

* corrections

* corrections

* Test1

* Swapping landing page vs concept

* fix links

* Fix links

* Fix desc
2020-09-01 16:26:21 -07:00

2.4 KiB

title, ms.date, dev_langs, helpviewer_keywords, ms.assetid
title ms.date dev_langs helpviewer_keywords ms.assetid
How to: Create Thumbnail Images 03/30/2017
csharp
vb
thumbnail images [Windows Forms], creating
images [Windows Forms], creating thumbnails
e956242a-1e5b-4217-a3cf-5f3fb45d00ba

How to: Create Thumbnail Images

A thumbnail image is a small version of an image. You can create a thumbnail image by calling the xref:System.Drawing.Image.GetThumbnailImage%2A method of an xref:System.Drawing.Image object.

Example

The following example constructs an xref:System.Drawing.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:

Screenshot that shows the output thumbnail.

Note

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

[!code-csharpSystem.Drawing.WorkingWithImages#71] [!code-vbSystem.Drawing.WorkingWithImages#71]

Compiling the Code

The preceding example is designed for use with Windows Forms, and it requires xref:System.Windows.Forms.PaintEventArgs e, which is a parameter of the xref:System.Windows.Forms.Control.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 xref:System.Windows.Forms.Control.Paint event

  4. In the xref:System.Windows.Forms.Control.Paint handler, call the GetThumbnail method and pass e for xref:System.Windows.Forms.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.

See also