#define ULONG_PTR void*
#include<gdiplus.h>
#include<GdiPlusEnums.h>
#pragma comment(lib,"GdiPlus.lib")
using namespace Gdiplus;
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
GdiplusStartupInput gdiplusStartupInput;
ULONG_PTR gdiplusToken;
GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
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);
GdiplusShutdown(gdiplusToken);
return -1; // Failure
}
void BMP2JPG(CString strBMPFile,CString strJPGFile)
{
CLSID encoderClsid;
WCHAR strGuid[39];
if(GetEncoderClsid(L"image/jpeg", &encoderClsid) >= 0)
StringFromGUID2(encoderClsid, strGuid, 39);
Image image(strBMPFile.AllocSysString());
image.Save(strJPGFile.AllocSysString(),&encoderClsid,NULL);
}
posted on 2007-02-27 19:26
飞鸟 阅读(2349)
评论(7) 编辑 收藏 所属分类:
VC