Use of gdiplus in vc6.0 and a small example

Source: Internet
Author: User

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;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.