This documentation is archived and is not being maintained.

SimpleImage Sample: Loads, Resizes, Converts, and Saves Images

Visual Studio 2008

The SimpleImage sample shows how to use the CImage class to load, display, and save a variety of different image formats, including .bmp, .gif, .jpg, and .png. It shows how CImage can be used to manipulate the image in various ways, and how to extract information about the image. SimpleImage uses the CFileDialog class to present the user with the standard Windows dialog boxes for loading and saving files of various formats. The sample creates a docking toolbar using the CToolBar class. The toolbar displays a set of buttons for resizing the image.

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 get samples and instructions for installing them:

  • On the Visual Studio Help menu, click Samples.

    For more information, see Visual Studio Samples.

  • The most recent version and complete list of samples is available online from the Visual Studio 2008 Samples page.

  • You can also locate samples on your computer's hard disk. By default, samples and a Readme file are copied into a folder under \Program Files\Visual Studio 9.0\Samples\. For Express editions of Visual Studio, all samples are located online.

To build and run the SimpleImage sample

  1. Open the solution SimpleImage.sln.

  2. On the Build menu, click Build.

  3. On the Debug menu, click Start Without Debugging.

The sample is a simple application that allows you to do the following:

  • Load an image from disk in a variety of formats.

  • Resize the image and convert it from color to grayscale.

  • Save the image in several image formats.

  • This sample demonstrates the following classes:

    CImage, CString, CPaintDC, CDialog, CFileDialog, CToolBar, CStatic

  • This sample demonstrates the following keywords:

    CToolBar::SetButtonInfo, CToolBar::SetButtons, CToolBar::LoadToolBar, CToolBar::EnableDocking, CImage::GetWidth, CImage::GetHeight, CImage::StretchBlt, CImage::GetExporterFilterSting, CImage::Load, CImage::Save, CImage::IsIndexed, CImage::GetPixel, CImage::SetPixelRGB, CImage::GetMaxColorTableEntries, CImage::GetColorTable, CImage::IsNull, CImage::GetBPP, CImage::IsDIBSection, CImage::GetPitch, CCmdUI::Enable, CCmdUI::SetCheck, CStatic::SendMessage, CWnd::GetClientRect, CWnd::GetDlgItem, sprintf_s

Other Resources

Show: