GDI+ Images Sample
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here. ArchiveDisclaimer

GDI+ Images Sample 

Download sample

This sample application shows how to manipulate images using GDI+.

Security noteSecurity Note

This sample code is provided to illustrate a concept and should not be used in applications or Web sites, as it may not illustrate the safest coding practices. Microsoft assumes no liability for incidental or consequential damages should the sample code be used for purposes other than as intended.

To open the sample file in Solution Explorer

  1. Click Download Sample.

    The File Download message box appears.

  2. Click Open, and on the left column of the zip folder window, click Extract all files.

    The Extraction Wizard opens.

  3. Click Next. You can change the directory that the files will be extracted to, and then click Next again.

  4. Make sure that the Show extracted files check box is selected, and click Finish.

  5. Double-click the sample's .sln file.

    The sample solution is displayed in Solution Explorer. You might get a security warning that says the solution location is not trusted. Click OK to continue.

To run this sample

  • Press F5.


The following ideas are demonstrated in this sample:

  • Zoom   The zoom feature changes the size of an image on the screen. The amount of zooming performed is generally expressed as a percentage of the original size of the image. Zooming does not change the size of the original image, only the image size that appears on the screen. This is demonstrated in the Zoom method of this sample.

  • Resize   The resize feature changes the actual size of the image. Both the width and height are changed based on a resize ratio. This is demonstrated in the ResizeImage method of this sample.

  • Flip and Rotate   Flipping reflects an image across either the x- or y-axis. The result is either a mirror image or an upside-down image. Rotating pivots the image a certain number of degrees about its center. For images, it is most common to rotate in multiples of 90 degrees. Rotating and flipping are demonstrated in the RotateFlip method of this sample.

  • Negative and Grayscale   Creating a negative or grayscale image is done using a ColorMatrix. When applied to an image, the ColorMatrix is the basis for a color transformation. This is demonstrated in the DrawNegativeImage and ConverttoGrayScale methods of this sample.

  • Crop   Cropping takes a region of an image and makes that region into its own separate image. This is demonstrated in the CropButton_Click method of this sample.

  • Thumbnails   Images can be saved either in their normal size or as a thumbnail. One way to create a thumbnail is to create a clone of the image, resize it, and save the clone as a thumbnail. This is demonstrated in the SaveThumbnailAs_Click method of this sample.

See Also

© 2016 Microsoft