C# 如何读取不在前台的应用程序的屏幕像素?

C# 如何读取不在前台的应用程序的屏幕像素?,c#,.net,windows,drawing,screen,C#,.net,Windows,Drawing,Screen,我目前拥有的代码非常适合读取屏幕上显示的任何内容的像素颜色,其摘录如下所示: using (Bitmap bmpScreenCapture = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height)) { using (Graphics g = Graphics.FromImage(bmpScreenCapture)) { g.CopyFromScreen(Screen.

我目前拥有的代码非常适合读取屏幕上显示的任何内容的像素颜色,其摘录如下所示:

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);
}
但是,要使其工作,我正在检查的窗口必须是屏幕上显示的任何窗口。如果我把另一个窗口带到前台,那么我的代码就不起作用了,因为它当然在监视屏幕像素

如何使我的代码能够在窗口位于其他窗口之后时,继续读取与我要监视的程序相关联的顶部窗口的像素?多谢各位