类似地,用pDC->StretchBlt来缩放,只是加上了两个参数,原始位图的宽高。
void CMy1_showbitmapView::StretchBitMap(CDC * pDC)
{
//CBitmap对象
CBitmap bitmap;
//CDC对象
CDC dcMemory;
//加载资源
bitmap.LoadBitmapW(IDB_BITMAP1);
//创建内存设备环境
dcMemory.CreateCompatibleDC(pDC);
//将位图选入内存设备环境
dcMemory.SelectObject(&bitmap);
//将内存设备环境复制到真正的设备环境中
pDC->BitBlt(0, 0, 512, 320, &dcMemory, 0, 0, SRCCOPY);
//缩小一半显示
pDC->StretchBlt(512, 0, 512 / 2, 320 / 2, &dcMemory, 0, 0, 512, 320, SRCCOPY);
pDC->StretchBlt(512, 320/2, 512 / 2, 320 / 2, &dcMemory, 0, 0, 512, 320, SRCCOPY);
}
void CMy1_showbitmapView::OnDraw(CDC* pDC)
{
CMy1_showbitmapDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
if (!pDoc)
return;
// TODO: add draw code for native data here
this->StretchBitMap(pDC);
}
运行结果如下: