如何使用aero加速BitBlt捕获屏幕?

时间:2011-08-12 17:44:52

标签: visual-c++ gdi screen-capture bitblt

我使用以下代码来捕获具有GDI函数的屏幕:

// Prologue:

int iScreenWidth = GetSystemMetrics(SM_CXSCREEN);
int iScreenHeight = GetSystemMetrics(SM_CYSCREEN);

HDC hScreenDC = GetDC(0);
HDC hCaptureDC = CreateCompatibleDC(hScreenDC);
HBITMAP hCaptureBitmap = CreateCompatibleBitmap(hScreenDC, iScreenWidth, iScreenHeight);
HBITMAP hOldBitmap = (HBITMAP)SelectObject(hCaptureDC, hCaptureBitmap);

// Capture:

BitBlt(hCaptureDC, 0, 0, iScreenWidth, iScreenHeight, hScreenDC, 0, 0, SRCCOPY);

// --- ... --- //

// Epilogue:

SelectObject(hCaptureDC, hOldBitmap);
DeleteObject(hCaptureBitmap);
DeleteDC(hCaptureDC);
ReleaseDC(0, hScreenDC);

问题是:当Aero打开时,BitBlt功能 WAY 慢 - 它需要将近50毫秒(这对我来说是不可接受的,因为我需要在第二秒内多次捕获)。

BitBlt直接从视频硬件获取像素数据。但是在我的测试机器(即Radeon 5470和Radeon 4850)中显卡非常好,所以我不明白什么是错的。我知道这些卡(任何现代卡)在2D中并不像3D那样好,但我认为简单的blit操作不应该花费50ms。

那么,请你建议怎么做?任何一种“hackish”解决方案(只要它稳定工作)都可以做到。

目标系统是Win7 x64,32位代码。

提前致谢!

1 个答案:

答案 0 :(得分:0)

BitBlt performance with Aero enabled是相关的。 还有一种Windows方法可以禁用aero。我也一直遇到从航空中获得超过15 fps的问题。怪异。