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

时间:2020-09-09 09:49:28

标签: 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.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;
        }

出于搜索像素的目的,但这效率不高,因为我的窗口尺寸很小,并且由于我要查找的像素属于移动应用程序内的对象,因此它可以找到对象在哪里,而不是在哪里是的。

0 个答案:

没有答案