CImage is a Mfc/atl shared class defined in Vc.net and an ATL tool class that provides enhanced (DDB and DIB) bitmap support for loading, displaying, converting, and saving image files in a variety of formats, including BMP, GIF, JPG, PNG, TIF, and more. CImage is a separate class, without a base class. (CImage class is based on GDI +, from the introduction of Vc.net, VC 6.0 does not.) )
ATL (Active Template Library, Activity Templates Gallery) is a set of template-based C + + classes that simplify the writing of small, fast COM objects.
In order to use the CImage class in an MFC program, you must include an ATL image header file Atlimage.h: (not included in VS08 SP1)
#include <atlimage.h>
This is a powerful image processing class, the following are detailed in the document, the dialog box under the display picture.
For single-Document programs:
Step One: Add the header file (since I am using VS2008SP1, I have not added the header file above.) )
Step two: Declare the object in the doc header file, such as: CImage img;
Step three: Serializing the Serialize function inside the DOC implementation function
void Cimagepngdoc::serialize (carchive& ar)
{
if (AR. IsStoring ())
{
TODO: Add storage code here
}
Else
{
TODO: Add the Load code here
if (!img. IsNull ()) img. Destroy ();
Img. Load (AR. GetFile ()->getfilepath ());
}
}
Step four: In the implementation file OnDraw () of the views view
void Cimagepngview::ondraw (cdc* pDC)
{
cimagepngdoc* PDoc = GetDocument ();
Assert_valid (PDOC);
if (!pdoc)
Return
TODO: Add drawing code here for native data
if (!pdoc->img. IsNull ()) pdoc->img. Draw (PDC->M_HDC, 0, 0);
}
Complete, the above can display most of the picture formats.
For dialog box programs:
Step one: Declare an object in the header file of the dialog box, such as: CImage img;
Step Two:add a picture to the Dlg Control,type set to Rectangle
Step three: Inside the implementation function OnPaint () Function of the dialog box (Use the Class Wizard to reload OnPaint)
1 voidCdrawpicturedlg::onpaint ()2 {3CPAINTDC DC ( This);//device context for painting4 Cdialog::onpaint (); 5Cdialog::updatewindow ();//Update Windows window, if there is no such pace, the picture shows that there will be problems6 7 CImage img;8 if(!img. IsNull ()) img. Destroy ();9Img. Load (_t ("e:\\visual Studio 2010\\projects\\loaddlldemo\\img\\skin\\111.jpg")); Ten if(!img. IsNull ()) One { A CRect rect; -CDC *PDC = GetDlgItem (idc_static_pic),GetDC (); -HDC hdc= pdc->Getsafehdc (); theGetDlgItem (Idc_static_pic)->getclientrect (&rect); -Img. Draw (DC.M_HDC,0,0);//draw a picture directly on the dialog box - //img. Draw (HDC, 0, 0);//draw a picture on the Picturecontrol - ReleaseDC (PDC); + } -}
View Code
Use the CImage class to display PNG, JPG, and other pictures