BitBlt不能变尺寸,但是StrectchBlt可以变尺寸,在使用StrectchBlt时要注意,首先要设置一下SetStretchBltMode,通常设成HALFTONE,这样缩放时就不会失真。
SetStretchBltMode 模式可以参考:
http://blog.csdn.net/hgy413/article/details/6785513
推荐HALFTONE, 但可能会消耗资源一点.
1 void CAnalysisVideoPlayerDlg::DrawImage( HBITMAP hbitmap, int x, int y, CDC *pDC, int nSrcW, int nSrcH) 2 { 3 HBITMAP OldBitmap; 4 CDC MemDC; 5 MemDC.CreateCompatibleDC(pDC); 6 OldBitmap=(HBITMAP)MemDC.SelectObject(hbitmap); 7 CRect rect; 8 GetClientRect(&rect); 9 if (pDC){ 10 pDC->SetStretchBltMode(HALFTONE); 11 //pDC->SetStretchBltMode(COLORONCOLOR); 12 pDC->StretchBlt(x, y, rect.Width(), rect.Height(), &MemDC, 0, 0, nSrcW, nSrcH, SRCCOPY); 13 //pDC->BitBlt(x,y,rect.Width(),rect.Height(),&MemDC,0,0,SRCCOPY); 14 } else { 15 ASSERT(0); 16 } 17 MemDC.SelectObject(OldBitmap); 18 ReleaseDC(&MemDC); 19 }
使用示例.