目前我用它来查找屏幕上另一个图像中出现的位图,即一个窗口,但它的工具很慢,我希望它花费 1 秒或更短的时间,我正在考虑将图像裁剪成一个部分,即 80,60在图像的 0,0 点处的部分并在那里搜索,当它完成时,它会进行相同的裁剪,但 y+60 并继续,直到它覆盖了整个图像,假设它是 800 x 600 像素
我目前使用的代码是:
        public bool findImage(Bitmap small, Bitmap large, out Point location)
    {
        //Loop through large images width
        for (int largeX = 0; largeX < large.Width; largeX++)
        {
            //And height
            for (int largeY = 0; largeY < large.Height; largeY++)
            {
                //Loop through the small width
                for (int smallX = 0; smallX < small.Width; smallX++)
                {
                    //And height
                    for (int smallY = 0; smallY < small.Height; smallY++)
                    {
                        //Get current pixels for both image
                        Color currentSmall = small.GetPixel(smallX, smallY);
                        Color currentLarge = large.GetPixel(largeX + smallX, largeY + smallY);
                        //If they dont match (i.e. the image is not there)
                        if (!colorsMatch(currentSmall, currentLarge))
                            //Goto the next pixel in the large image
                            goto nextLoop;
                    }
                }
                //If all the pixels match up, then return true and change Point location to the top left co-ordinates where it was found
                location = new Point(largeX, largeY);
                return true;
            //Go to next pixel on large image
            nextLoop:
                continue;
            }
        }
        //Return false if image is not found, and set an empty point
        location = Point.Empty;
        return false;
    }