当我想使用Windows API获取使用RLE压缩的屏幕截图时,我遇到了问题。 我使用的是Qt / C ++。
这是我的代码:
void Screenshot::captureScreenCompressed() {
HWND hDesktopWnd = GetDesktopWindow();
HDC hDesktopDC = GetDC(hDesktopWnd);
HDC hCaptureDC = CreateCompatibleDC(hDesktopDC);
HBITMAP hCaptureBitmap = CreateCompatibleBitmap(hDesktopDC, _screenWidth, _screenHeight);
SelectObject(hCaptureDC, hCaptureBitmap);
BitBlt(hCaptureDC, 0, 0, _screenWidth, _screenHeight, hDesktopDC, 0,0, SRCCOPY | CAPTUREBLT);
BITMAPINFO bmi = {0};
bmi.bmiHeader.biSize = sizeof(bmi.bmiHeader);
bmi.bmiHeader.biWidth = _screenWidth;
bmi.bmiHeader.biHeight = - _screenHeight;
bmi.bmiHeader.biPlanes = 1;
bmi.bmiHeader.biBitCount = 32;
bmi.bmiHeader.biCompression = BI_RLE4;
if (GetDIBits(hCaptureDC, hCaptureBitmap, 0, _screenHeight, NULL, &bmi, DIB_RGB_COLORS) == 0) {
qDebug() << "Problem on Compression";
}
ReleaseDC(hDesktopWnd, hDesktopDC);
DeleteDC(hCaptureDC);
DeleteObject(hCaptureBitmap);
}
最终sizeImage为0,getDiBits函数返回0。 我需要一些帮助,谢谢!