所以我正在玩stretchblt,当我部分捕捉到我的屏幕时,我注意到了一种奇怪的相关性。只要捕获的尺寸匹配常用的分辨率(比如{0,0,224,144}的RECT),我会得到这样的结果: 244x144 Res
但是,如果我将尺寸更改一个像素(比如{0,0,225,144}的RECT),我会得到这样的结果:255x144
这是一个代码示例,如果有必要的话。我真的可以使用一些洞察力来解释为什么会这样。谢谢你的帮助!
void CaptureScreen(RECT imageDim, std::vector<uint8_t>& vecData)
{
BYTE* pScreenData = nullptr;
LONG mapWidth = imageDim.right - imageDim.left;
LONG mapHeight = imageDim.bottom - imageDim.top;
HDC desktopDC = GetDC(NULL);
HDC captureDC = CreateCompatibleDC(desktopDC);
BITMAPINFO bmpInfo;
bmpInfo.bmiHeader.biSize = sizeof(bmpInfo.bmiHeader);
bmpInfo.bmiHeader.biPlanes = 1;
bmpInfo.bmiHeader.biBitCount = 24;
bmpInfo.bmiHeader.biCompression = BI_RGB;
bmpInfo.bmiHeader.biClrUsed = 0;
bmpInfo.bmiHeader.biClrImportant = 0;
bmpInfo.bmiHeader.biWidth = mapWidth;
bmpInfo.bmiHeader.biHeight = mapHeight;
bmpInfo.bmiHeader.biSizeImage = mapWidth*mapHeight * 3;
HBITMAP hBitmap = CreateDIBSection(captureDC, &bmpInfo, DIB_RGB_COLORS, (void**)(&pScreenData), NULL, NULL);
SelectObject(captureDC, hBitmap);
StretchBlt(captureDC, // Destination device context
0, // x-coordinate of destination rect
mapHeight, // y-coordinate of destination rect
mapWidth, // width of destination rect
-mapHeight, // height of destination rect
desktopDC, // Desktop device context
imageDim.left, // x-coordinate of source rectangle
imageDim.top, // y-coordinate of source rectangle
mapWidth, // width of source rect
mapHeight, // height of source rect
SRCCOPY);
DeleteObject(hBitmap);
SaveImage(pScreenData, imageDim);
}