1. You need to download the SDK for gdiplus.
2. set the header file path under tool, option, direction, and include files... /Microsoft SDK/include, set the Lib path under tool, option, direction, libaray files... /Microsoft SDK/sdk8/lib, enter gdiplus in project, setting, Link, object/modules libaray. lib.
Note: The path must be placed at the top, and it must be an absolute path. You must complete the above...
3. Create a single document project XXX and add member variables to the xxxapp class
Protected:
Gdiplusstartupinput m_gdiplusstartupinput;
Ulong_ptr m_gdiplustoken;
Add gdiplusstartup (& m_gdiplustoken, & m_gdiplusstartupinput, null) in xxxapp: initinstance );
Overload xxxapp: exitinstance () and add: gdiplusshutdown (m_gdiplustoken );
Note: add the following statement before the modified file:
# Include <gdiplus. h>
Using namespace gdiplus;
After the above steps are completed, you can use gdiplus in the program. Below is a small example of converting BMP into JPG:
Int getencoderclsid (const wchar * format, CLSID * pclsid)
{
Uint num = 0; // Number of image encoders
Uint size = 0; // size of the image encoder array in bytes
Imagecodecinfo * pimagecodecinfo = NULL;
Getimageencoderssize (& num, & size );
If (size = 0)
Return-1; // failure
Pimagecodecinfo = (imagecodecinfo *) (malloc (size ));
If (pimagecodecinfo = NULL)
Return-1; // failure
Getimageencoders (Num, size, pimagecodecinfo );
For (uint J = 0; j <num; ++ J)
{
If (wcscmp (pimagecodecinfo [J]. mimetype, format) = 0)
{
* Pclsid = pimagecodecinfo [J]. CLSID;
Free (pimagecodecinfo );
Return J; // success
}
}
Free (pimagecodecinfo );
Return-1; // failure
}
Void BMP 2jpg (cstring strbmp file, cstring strjpgfile)
{
CLSID encoderclsid;
Wchar strguid [39];
If (getencoderclsid (L "image/JPEG", & encoderclsid)> = 0)
Stringfromguid2 (encoderclsid, strguid, 39 );
Image image (strbmp file. allocsysstring ());
Image. Save (strjpgfile. allocsysstring (), & encoderclsid, null );
}
Of course, you must add
# Include <gdiplus. h>
Using namespace gdiplus;