How to read the screen pixels?

后端 未结 5 1673
被撕碎了的回忆
被撕碎了的回忆 2020-12-01 08:17

I want to read a rectangular area, or whole screen pixels. As if screenshot button was pressed.

How i do this?

Edit: Working code:



        
5条回答
  •  心在旅途
    2020-12-01 09:12

    Rereading your question, it sounds like we may have gotten off on a tangent with the screen capture. If you just want to check some pixels on the screen, you can use GetPixel.

    HDC hdcScreen = ::GetDC(NULL);
    COLORREF pixel = ::GetPixel(hdcScreen, x, y);
    ReleaseDC(NULL, hdcScreen);
    if (pixel != CLR_INVALID) {
      int red = GetRValue(pixel);
      int green = GetGValue(pixel);
      int blue = GetBValue(pixel);
      ...
    } else {
      // Error, x and y were outside the clipping region.
    }
    

    If you're going to read a lot of pixels, then you're better off with a screen capture and then using GetDIBits. Calling GetPixel zillions of times will be slow.

提交回复
热议问题