改变bitmap大小的函数

BOOL TranslateBitmapSize( IN HDC hCurScreemDC, //当前屏幕DC,可通过GetDC获得 IN HBITMAP hBmpSrc, //原BITMAP句柄 IN int nSrcWidth, //原BITMAP的宽度 IN int nSrcHeight, //原BITMAP的高度 OUT HBITMAP &hBmpDst, //改变大小后的BITMAP的句柄 IN int nDstWidth, //改变大小后的BITMAP的宽度 IN int nDstHeight //改变大小后的BITMAP的高度 ) { if (hBmpSrc == NULL || hCurScreemDC == NULL) { return FALSE; } if (hBmpDst != NULL) { DeleteObject(hBmpDst); } HDC hOldSrcDC = NULL; HDC hOldDstDC = NULL; HDC hSrcDC = CreateCompatibleDC(hCurScreemDC); HDC hDstDC = CreateCompatibleDC(hCurScreemDC); hBmpDst = CreateCompatibleBitmap(hCurScreemDC,nDstWidth,nDstHeight); hOldSrcDC = (HDC)SelectObject(hSrcDC,hBmpSrc); hOldDstDC = (HDC)SelectObject(hDstDC,hBmpDst); StretchBlt(hDstDC,0,0,nDstWidth,nDstHeight,hSrcDC,0,0,nSrcWidth,nSrcHeight,SRCCOPY); SelectObject(hSrcDC,hOldSrcDC); SelectObject(hDstDC,hOldDstDC); DeleteObject(hSrcDC); DeleteObject(hDstDC); return TRUE; }

 

原理:

 

创建两个与当前屏幕DC兼容的DC,创建一个与当前屏幕兼容的位图句柄,把两个位图句柄分别选入两个兼容DC,然后通过StretchBlt函数进行DC拷贝,目的位图句柄就获得了改变后的位图。

你可能感兴趣的:(函数)