Labels:

CImage is a class provides enhanced bitmap support, including the ability to load and save images in JPEG, GIF, BMP, PNG, TIFF and some other formats. CImage is part of the ATL. But we can share it in MFC.

For Sharing the CImage With MFC, We need to include the header file,

#include "atlimage.h"
#include "atltypes.h" (Optional)

Load Image in to CImage

To load an image to the CImage two formats are available,

1.HRESULT Load(LPCTSTR pszFileName);

Where,
pszFileName -- A pointer to a string containing the name of the image file to load.

2.HRESULT Load(IStream* pStream);

Where,
pStream -- A pointer to a stream containing the name of the image file to load.

Example:

CImage img;
img.Load("C:\images\sample.tiff");


Save Image From CImage

To Save an image in CImage two formats available,

1.HRESULT Save(IStream* pStream,REFGUID guidFileType);

2.HRESULT Save(LPCTSTR pszFileName,REFGUID guidFileType= GUID_NULL);

where,
pStream -- A pointer to a COM IStream object containing the file image data.
pszFileName -- A pointer to the file name for the image.
guidFileType -- The file type to save the image .

Example:

img.Save("D:\\images.bmp");