How to read screen pixels for an application that is not in the foreground?

本秂侑毒 提交于 2019-12-10 10:59:22

问题


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.

来源:https://stackoverflow.com/questions/43548901/how-to-read-screen-pixels-for-an-application-that-is-not-in-the-foreground

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!