|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
This sample application shows how to manipulate images using GDI+.
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
Click Download Sample.
The File Download message box appears.
Click Open, and on the left column of the zip folder window, click Extract all files.
The Extraction Wizard opens.
Click Next. You can change the directory that the files will be extracted to, and then click Next again.
Make sure that the Show extracted files check box is selected, and click Finish.
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
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. 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.