HBITMAP CBmpList::ZoomBitmap(CClientDC* pDC, CString csFile, double dx, double dy)
{
if (NULL == pDC || !PathFileExists(csFile) || dx < 0 || dy < 0)
{
return NULL;
}
CBitmap cbmp;
HBITMAP hBitmap = NULL;
hBitmap = (HBITMAP)LoadImage(NULL, csFile, IMAGE_BITMAP, 0, 0,
LR_LOADFROMFILE | LR_CREATEDIBSECTION | LR_DEFAULTSIZE);
cbmp.Attach(hBitmap);
CDC memdc;
memdc.CreateCompatibleDC(pDC);
memdc.SelectObject(&cbmp);
memdc.SetStretchBltMode(COLORONCOLOR);
//获得位图参数
BITMAP bmp;
cbmp.GetBitmap(&bmp);
INT_PTR iW = (INT_PTR)(dx*bmp.bmWidth);
INT_PTR iH = (INT_PTR)(dy*bmp.bmHeight);
//缩放
pDC->StretchBlt(0,0, iW, iH,&memdc,0,0,
bmp.bmWidth,bmp.bmHeight,SRCCOPY);
// 将内存DC转存到新的CBitmap对象中
CBitmap newbmp;
newbmp.CreateCompatibleBitmap(pDC, iW, iH);
CDC MemDC;
MemDC.CreateCompatibleDC(pDC);
CBitmap *oldbitmap=MemDC.SelectObject(&newbmp);
MemDC.BitBlt(0,0, iW, iH, pDC,0,0,SRCCOPY);
MemDC.SelectObject(oldbitmap);
MemDC.DeleteDC();
return (HBITMAP)(newbmp.Detach());
}