* 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
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 |
|
|
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:
-
xref:System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor
-
xref:System.Drawing.Drawing2D.InterpolationMode.HighQualityBilinear
-
xref:System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic
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.
[!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.
