#include 
				<windows.h>#include <gdiplus.h>#include <stdio.h>#pragma comment(lib,"gdiplus.lib")

using namespace Gdiplus;

INT GetEncoderClsid(const WCHAR* format, CLSID* pClsid);   // helper function  
INT main()
{

// Initialize GDI+.
GdiplusStartupInput gdiplusStartupInput;
ULONG_PTR gdiplusToken;
GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);

CLSID encoderClsid;
Status stat;
Image* image = new Image(L"test.png");

// Get the CLSID of the PNG encoder.
GetEncoderClsid(L"image/bmp", &encoderClsid); //或者image/png image/jpeg等

stat = image->Save(L"test2.bmp", &encoderClsid, NULL);

if
(stat == Ok)
printf
("test2.png was saved successfully\n");
else

printf
("Failure: stat = %d\n", stat);

delete
image;
GdiplusShutdown(gdiplusToken);
return
0;
}



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
}