Noah Huber-Feely
Noah Huber-Feely

Reputation: 71

Simple way to get pixel data of coordinate on screen in windows

I am looking for a simple way to get the rgb value of any given coordinate on the screen in the windows 8 operating system. This is for a program to process and try to find patterns and objects on the screen, so all I need is for the gathered data to be placed into an array. The best case scenario is a function like getPixelData(int x, int y) that then returns the color data. I will be compiling the final program in Visual Studio 2008. No other question I found fitted this exact problem because they seemed to mainly talk about writing the data to an image file or they didn't explain where the file was for the mechanism to access the data. Here is a question that didn't give me the exact answer I was seeking, just to put my question in context. How to get Pixel data \ Pixel buffer from a window and extract RGB? If any one could help me with this it would be much appreciated, and if there is no simple solution then I am fine with something a bit harder. Also, if you need any more information about my question please ask. I haven't posted any source code, because I am simply looking for an addition to the code not fixing anything in the the preexisting code.

Upvotes: 1

Views: 7576

Answers (1)

Amadeusz
Amadeusz

Reputation: 1706

You have a great answer in the link you gave. The simpliest way is to use

COLORREF GetPixel(
  HDC hdc, 
  int nXPos, 
  int nYPos
);

To get screen HDC you can use this and how to get RGB values from COLORREF is vell described here.

More efficient way will be to get your entire screen at once using bitmap which is also described in the link you gave, but more "friendly" approach you can find here.

Upvotes: 1

Related Questions