当我使用下面的代码时,如果找不到我在图像中搜索的图像,则在完成循环之前大约需要3-5秒.当这是搜索时,程序的其余部分暂停,我的计时器不同步,看起来程序冻结了几秒钟.图像不是很大,"printscreen"约为344x354,"Ok"约为15x7.我知道这是因为for循环,但有没有更好的方法来做到这一点,或者我可以以某种方式除了程序的其余部分之外,他的程序部分,所以程序不会冻结几秒钟.
// Ok is the image I am searching for.
// printscreen is the image I am searching in.
Bitmap Ok = new Bitmap(Properties.Resources.popupok1);
int Count = 0;
for (int x = 0; x < printscreen.Width; x++)
{
for (int y = 0; y < printscreen.Height; y++)
{
Count = 0;
if (printscreen.GetPixel(x, y) == Ok.GetPixel(0, 0) &&
printscreen.GetPixel(x + 1, y) == Ok.GetPixel(1, 0))
{
for (int OkX = 0; OkX <= Ok.Width; OkX++)
{
for (int OkY = …Run Code Online (Sandbox Code Playgroud)