5

I use following code to capture the screen with GDI functions:

// 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);

The problem is: BitBlt function is WAY slow when Aero is turned on - it takes almost 50 milliseconds (which is unacceptable for me because I need to capture multiple times in second).

BitBlt gets the pixel data directly from video hardware. But video cards are pretty good in my test machines (namely Radeon 5470 and Radeon 4850), so I don't understand what's wrong. I know these cards (any modern cards) are not that good in 2D as they are in 3D, but that simple blit operation should not take 50ms anyway I think.

So, could you please advice what to do? Any kind of "hackish" solution (as long as it's stable working) would do in my case.

Target system is Win7 x64, 32-bit code.

Thanks in advance!

TX_
  • 51
  • 1
  • 2
  • 1
    In Aero, the desktop is composited from individual memory bitmaps of all the toplevel windows. It enables features like live window thumbnails and Aero Peek. This of course does not come for free and won't be in any way hardware accelerated for BitBlt. You really should turn on the CAPTUREBLT option. I doubt it makes much difference. – Hans Passant Aug 12 '11 at 18:52

1 Answers1

0

BitBlt performance with Aero enabled is related. Also there is a windows method to disable aero. I too have been having problems getting more than 15 fps out of aero. Weird.

Community
  • 1
  • 1
rogerdpack
  • 62,887
  • 36
  • 269
  • 388