I currently have code that works great to read the pixel colors for whatever is displayed on the screen, an excerpt of which is shown below:
using (Bitmap bmpScreenCapture = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height))
{
using (Graphics g = Graphics.FromImage(bmpScreenCapture))
{
g.CopyFromScreen(Screen.PrimaryScreen.Bounds.X, Screen.PrimaryScreen.Bounds.Y, 0, 0, bmpScreenCapture.Size, CopyPixelOperation.SourceCopy);
}
Color c = bmpScreenCapture.GetPixel(x,y);
}
For this to work, however, the window I am checking must be whatever is displayed on the screen. If I bring another window to the foreground, then my code does not work, because of course it is monitoring the screen pixels.
How can I make it so that my code can continue to read the pixels of the top window associated with the program I want to monitor when it's window is behind other windows? Thank you.