Hello, first post here!
I'm writing a C++ program using the Windows API that takes a screenshot of my monitor and calculates the average color of certain parts of the screen.
This is the routine I use to take a single screenshot of the monitor and create a matrix of pixel values (to be later used):
My understanding is that OBS uses the same API to capture the monitor on Windows, but of course it is much faster than mine, otherwise it wouldn't be as snappy as it is.
I looked in the source code to try to get some insight about how to make it fast, and I see many of the same calls I do in dc_capture_capture() in dc_capture.c, but I don't understand how it works overall.
Do you have any suggestion on how can I make my screen capture routine faster and mimik OBS's performance?
I apologize if this is not the correct forum for these kind of questions.
I'm writing a C++ program using the Windows API that takes a screenshot of my monitor and calculates the average color of certain parts of the screen.
This is the routine I use to take a single screenshot of the monitor and create a matrix of pixel values (to be later used):
I would like this program of mine to execute at 30FPS, so every 0.03 seconds I need to capture the screen and make my calculation. So far, the routine above executes in 0.02s on average, leaving little time to perform my calculation.void ScreenCap()
{
hScreen = GetDC(NULL);
hdcMem = CreateCompatibleDC(hScreen);
hBitmap = CreateCompatibleBitmap(hScreen, ScreenX, ScreenY);
hOld = SelectObject(hdcMem, hBitmap);
BitBlt(hdcMem, 0, 0, ScreenX, ScreenY, hScreen, 0, 0, SRCCOPY);
SelectObject(hdcMem, hOld);
GetDIBits(hdcMem, hBitmap, 0, ScreenY, ScreenData, (BITMAPINFO*)&bmi, DIB_RGB_COLORS);
ReleaseDC(GetDesktopWindow(), hScreen);
DeleteDC(hdcMem);
DeleteObject(hBitmap);
}
My understanding is that OBS uses the same API to capture the monitor on Windows, but of course it is much faster than mine, otherwise it wouldn't be as snappy as it is.
I looked in the source code to try to get some insight about how to make it fast, and I see many of the same calls I do in dc_capture_capture() in dc_capture.c, but I don't understand how it works overall.
Do you have any suggestion on how can I make my screen capture routine faster and mimik OBS's performance?
I apologize if this is not the correct forum for these kind of questions.