我目前的代码非常适合读取屏幕上显示的任何像素颜色,其摘录如下所示:
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);
}
然而,要使其工作,我正在检查的窗口必须是屏幕上显示的内容。如果我将另一个窗口带到前台,那么我的代码不起作用,因为它当然会监视屏幕像素。
如何使我的代码能够继续读取与我想要监视的程序相关联的顶部窗口的像素,当它的窗口位于其他窗口后面时?谢谢。