Use of gdiplus in vc6.0 and a small example of converting BMP to JPG

Source: Internet
Author: User
The use of gdiplus in vc6.0 and the http://mingarlic.blog.163.com/blog/static/31148911200710261318324/ of a small example of converting BMP to JPG

# Include <gdiplus. h>

Using namespace gdiplus;

Gdiplusstartupinput m_gdiplusstartupinput;
Ulong_ptr m_gdiplustoken;

Int getencoderclsid (const wchar * format, CLSID * pclsid );

Void BMP 2jpg (cstring strbmp file, cstring strjpgfile );

Gdiplusstartup (& m_gdiplustoken, & m_gdiplusstartupinput, null );

BMP 2jpg ("...","...");

Gdiplusshutdown (m_gdipluw.en );

 

 

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 );

}

 

/*

// In GDI +, You need to define a ulong_ptr.

# Ifndef ulong_ptr

# Define ulong_ptr unsigned long *

# Endif

*/
 

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.