我使用以下代码来调整 win32 HBITMAP 的大小。
HBITMAP ResizeBitmap(HDC hDC, HBITMAP source)
{
HDC hMemDC2 = CreateCompatibleDC(hDC);
HGDIOBJ hOld2 = SelectObject(hMemDC2, source);
BITMAP bitmap = { 0 };
GetObject(hBitmap, sizeof(BITMAP), &bitmap);
float SCALE = IMAGE_SCALE;
int nWidth = (int)ceil(bitmap.bmWidth / SCALE / 32) * 32;
int nHeight = (int)ceil(bitmap.bmHeight / SCALE / 32) * 32;
int dWidth = (int)round(bitmap.bmWidth / SCALE);
int dHeight = (int)round(bitmap.bmHeight / SCALE);
HDC hMemDC1 = CreateCompatibleDC(hDC);
HBITMAP hBitmap1 = CreateCompatibleBitmap(hDC, nWidth, nHeight);
HGDIOBJ hOld1 = SelectObject(hMemDC1, hBitmap1);
StretchBlt(hMemDC1, 0, 0, dWidth, dHeight, hMemDC2, 0, 0, bitmap.bmWidth, bitmap.bmHeight, SRCCOPY);
SelectObject(hMemDC1, hOld1);
SelectObject(hMemDC2, hOld2);
DeleteDC(hMemDC1);
DeleteDC(hMemDC2);
return hBitmap1;
}
和新图像(请忽略图像中的绿色矩形)
为什么?