Files
docs-desktop/dotnet-desktop-guide/framework/winforms/advanced/how-to-use-interpolation-mode-to-control-image-quality-during-scaling.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

3.0 KiB

title, ms.date, dev_langs, helpviewer_keywords, ms.assetid
title ms.date dev_langs helpviewer_keywords ms.assetid
How to: Use Interpolation Mode to Control Image Quality During Scaling 03/30/2017
csharp
vb
interpolation mode [Windows Forms], controlling image quality
images [Windows Forms], scaling
images [Windows Forms], controlling quality
fde9bccf-8aa5-4b0d-ba4b-788740627b02

How to: Use Interpolation Mode to Control Image Quality During Scaling

The interpolation mode of a xref:System.Drawing.Graphics object influences the way GDI+ scales (stretches and shrinks) images. The xref:System.Drawing.Drawing2D.InterpolationMode enumeration defines several interpolation modes, some of which are shown in the following list:

To stretch an image, each pixel in the original image must be mapped to a group of pixels in the larger image. To shrink an image, groups of pixels in the original image must be mapped to single pixels in the smaller image. The effectiveness of the algorithms that perform these mappings determines the quality of a scaled image. Algorithms that produce higher-quality scaled images tend to require more processing time. In the preceding list, xref:System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor is the lowest-quality mode and xref:System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic is the highest-quality mode.

To set the interpolation mode, assign one of the members of the xref:System.Drawing.Drawing2D.InterpolationMode enumeration to the xref:System.Drawing.Graphics.InterpolationMode%2A property of a xref:System.Drawing.Graphics object.

Example

The following example draws an image and then shrinks the image with three different interpolation modes.

The following illustration shows the original image and the three smaller images.

Screenshot that shows an image with varied interpolation settings.

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

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.

See also