1.头文件:
#include <INITGUID.h>
#include <imaging.h>
2.给对话框加上OnPaint() 方法,代码为:
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)))
{
if (SUCCEEDED(pImgFactory->CreateImageFromFile(L"//yes.jpg", &pImage)))
{
//CWindowDC dc(0);
CDC dcBitmap;
dcBitmap.CreateCompatibleDC(&dc);
hResult = CreateCompatibleBitmap(dc.GetSafeHdc(), width, heigth);
if (hResult) {
HGDIOBJ hOldBitmap = dcBitmap.SelectObject(hResult);
//pImage->GetThumbnail(0,0,&pImage);
pImage->Draw(dc.GetSafeHdc(), CRect(0, 0, width, heigth), NULL);
dcBitmap.SelectObject(hOldBitmap);
}
pImage->Release();
}
pImgFactory->Release();
}
CoUninitialize();
3.在CRect(0, 0, width, heigth)中设置图片的显示位置和大小
0,0为图片的左上点的坐标,width, heigth为右下点坐标