先转成BMP再取得HBITMAP
Image image(L"E:\\temp.png");
CLSID clsid;
GetEncoderClsid(L"image/bmp", &clsid);
image.Save(L"E:\\temp.bmp", &clsid, NULL);
Bitmap bmp(L"E:\\temp.bmp");
HBITMAP hBmp;
Color cr;
bmp.GetHBITMAP(&cr , hBmp);
...
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
}
时间问题,未经测试