1
目前我用它來找到一個位圖,發生在另一個圖像在屏幕上,即一個窗口,但它是工具慢,我想它需要1或更少的秒,我是考慮將圖像裁剪成一個部分,即在圖像0,0點處的一個80,60部分,然後在那裏進行搜索,如果它完成了相同的裁剪,但是y + 60並繼續,直到它覆蓋完整圖像它是800 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;
}
這可能是有趣的: http://stackoverflow.com/a/11004944/1373170 –