I am working on an idea that includes full screen capture, including windows and applications, analyzing it, and then drawing elements on the screen as an overlay.
I want to learn image processing techniques, and I could get a lot of data to work if I could access the Windows screen directly. I could use this to create automation tools that I have never seen before. More on this later.
My full-screen capture works for the most part.
HWND hwind = GetDesktopWindow(); HDC hdc = GetDC(hwind); int resx = GetSystemMetrics(SM_CXSCREEN); int resy = GetSystemMetrics(SM_CYSCREEN); int BitsPerPixel = GetDeviceCaps(hdc,BITSPIXEL); HDC hdc2 = CreateCompatibleDC(hdc); BITMAPINFO info; info.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); info.bmiHeader.biWidth = resx; info.bmiHeader.biHeight = resy; info.bmiHeader.biPlanes = 1; info.bmiHeader.biBitCount = BitsPerPixel; info.bmiHeader.biCompression = BI_RGB; void *data; hbitmap = CreateDIBSection(hdc2,&info,DIB_RGB_COLORS,(void**)&data,0,0); SelectObject(hdc2,hbitmap);
Once this is done, I can repeat this:
BitBlt(hdc2,0,0,resx,resy,hdc,0,0,SRCCOPY);
Cleanup code (I don't know if this is correct):
DeleteObject(hbitmap); ReleaseDC(hwind,hdc); if (hdc2) { DeleteDC(hdc2); }
Each time BitBlt is called, it captures the screen and saves it in memory, I can access through data .
Performance is somewhat satisfactory. BitBlt runs in 50 milliseconds (sometimes up to 33 ms) at 1920x1200x32.
What surprises me is that when I switch the display mode to 16 bit, 1920x1200x16, either using my graphics settings in advance or using ChangeDisplaySettings , I get a significantly improved screen capture time between 1 ms and 2 ms, which cannot be explained in bit depth is reduced twice. Using CreateDIBSection (as indicated above) provides significant speed in 16-bit mode compared to the CreateCompatibleBitmap setting (6-7 ms / f).
Does anyone know why falling to 16 bits causes such an increase in speed? Is there any hope that I can capture 32 bits at that speed? if not for color depth, but in order not to force changing screen buffer modes and terrible flicker.