PHP
·
发表于 5年以前
·
阅读量:8286
int GetEncoderClsid(const WCHAR* format, CLSID* pClsid)
{
UINT num = 0;
UINT size = 0;
ImageCodecInfo* pImageCodecInfo = NULL;
GetImageEncodersSize(&num, &size);
if(size == 0) return -1;
pImageCodecInfo = (ImageCodecInfo*)(malloc(size));
if(pImageCodecInfo == NULL) return -1;
//获取所有的图像编码器信息
GetImageEncoders(num, size, pImageCodecInfo);
//查找符合的图像编码器的Clsid
for(UINT j = 0; j < num; ++j)
{
OutputDebugString(pImageCodecInfo[j].MimeType);
if( wcscmp(pImageCodecInfo[j].MimeType, format) == 0 )
{
if (pClsid)
{
*pClsid = pImageCodecInfo[j].Clsid;
free(pImageCodecInfo);
return j; // Success
}
}
}
free(pImageCodecInfo);
return -1;
}
BOOL CUIHelper::SaveBitmapToFile(HBITMAP hBitmap, LPCWSTR lpFileName)
{
if (hBitmap)
{
CLSID sImageId;
if (GetEncoderClsid(L"image/bmp", &sImageId) >= 0)
{
Bitmap bitmap(hBitmap, NULL);
bitmap.Save(lpFileName, &sImageId, NULL);
}
}
return TRUE;
}