* 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
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 |
|
|
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:
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:
-
Create a new Windows Forms application.
-
Add the example code to the form.
-
Create a handler for the form's xref:System.Windows.Forms.Control.Paint event
-
In the xref:System.Windows.Forms.Control.Paint handler, call the
GetThumbnailmethod and passefor xref:System.Windows.Forms.PaintEventArgs. -
Find an image file that you want to make a thumbnail of.
-
In the
GetThumbnailmethod, specify the path and file name to your image. -
Press F5 to run the example.
A 100 by 100 thumbnail image appears on the form.