|
用IImage 接口
HBITMAP CImageLoader::loadImageFile( CString &strFileName)
{
IImagingFactory *pImgFactory =NULL;
IImage *pImage =NULL;
CoInitializeEx(NULL,COINIT_MULTITHREADED);
HBITMAP hResult =0;
if (SUCCEEDED(CoCreateInstance(CLSID_ImagingFactory,
NULL,
CLSCTX_INPROC_SERVER,
IID_IImagingFactory,
(void **)&pImgFactory)))
{
ImageInfo imageInfo;
if(SUCCEEDED(pImgFactory->CreateImageFromFile(strFileName,&pImage))
&& SUCCEEDED(pImage->GetImageInfo(&imageInfo)))
{
CWindowDC dc(0);
CDC dcBitmap;
dcBitmap.CreateCompatibleDC(&dc);
hResult =CreateCompatibleBitmap(dc.GetSafeHdc(),imageInfo.Width,imageInfo.Height);
if(hResult){
HGDIOBJ hOldBitmap = dcBitmap.SelectObject(hResult);
pImage->Draw(dcBitmap.GetSafeHdc(),CRect(0,0,imageInfo.Width,imageInfo.Height),NULL);
dcBitmap.SelectObject(hOldBitmap);
}
pImage->Release();
}
pImgFactory->Release();
CoUninitialize();
return hResult;
}
} |
|