C# 如何获取应用程序的位图而不是屏幕?

C# 如何获取应用程序的位图而不是屏幕?,c#,C#,目前,我正在使用以下方法创建整个屏幕的位图: Bitmap bm = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height); Graphics graphics = Graphics.FromImage(bm as Image); graphics.CopyFromScreen(0, 0, 0, 0, bm.S

目前,我正在使用以下方法创建整个屏幕的位图:

 Bitmap bm = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);
            
            Graphics graphics = Graphics.FromImage(bm as Image);

            graphics.CopyFromScreen(0, 0, 0, 0, bm.Size);
然后我在寻找这样的像素:

   for (int x = 0; x < Screen.PrimaryScreen.Bounds.Width; x++)
            {
                for (int y = 0; y < Screen.PrimaryScreen.Bounds.Height; y++)
                {
                    Color currentPixelColor = bm.GetPixel(x, y);

                    if (desiredPixelColor  == currentPixelColor)
                    {

                        Console.WriteLine("Found pixel - - - ");
                        Click(x, y);
                        return true;
                    }
                    
                        
                }
            }
            return false;
        }
for(int x=0;x

为了搜索像素,但这是低效的,因为我的窗口大小非常小,而且我正在寻找的像素属于移动应用程序中的对象,它会找到对象所在的位置,而不是它所在的位置。

这不只是将
Screen.PrimaryScreen.Bounds
CopyFromScreen
的参数替换为窗口的边界和位置,而不是整个屏幕?或者您的问题是您试图扫描的窗口是另一个应用程序?请注意,有