Any quick and easy way to capture a portion of the screen? getPixel was slow and GetDIBits seemed a little confusing as a start

I tried to use some code to capture a portion of the screen using getPixel on Windows, with the device context being null (to capture a screen instead of a window), but it was very slow. It looks like GetDIBits () might be fast, but it seems to get a little more complicated ... I wonder if there is a library that can put the whole area into an array and pixel [x] [y] will return a 24-bit color code of the pixel?

Or does such a library exist on Mac? Or if Ruby or Python already have a library like this that can do this?

0


a source to share


1 answer


I've never done this, but I would try:

  • Create a storage device context (DC) using CreateCompatibleDC passing it Desktop Device Context (GetDC (NULL)).

  • Create a bitmap (using CreateCompatibleBitmap) the same size as your capture area.

  • Select the bitmap in DC. (using SelectObject).

  • Make BitBlt from the DC to DC desktop you created (using the SRCCOPY flag).



Working with Device Contexts can leak GDI if you do something in the wrong order, so make sure you read the documentation for all the GDI functions you use (e.g. SelectObject, GetDC, etc.).

+3


a source







All Articles