gpt4 book ai didi

C#颜色检测多于一个结果

转载 作者:太空宇宙 更新时间:2023-11-03 23:02:45 25 4
gpt4 key购买 nike

我有一个关于颜色检测的问题。我有代码,但我想要不止一个结果。该代码很有名,但我想让程序给我带来所有结果,而不仅仅是一个结果。我希望我说清楚了。

不好意思我做了丢失的副本

private Boolean FindBitmap(Bitmap bmpNeedle, Bitmap bmpHaystack, out Point location)
{
try
{

for (int outerX = 0; outerX < bmpHaystack.Width - bmpNeedle.Width; outerX++)
{
for (int outerY = 0; outerY < bmpHaystack.Height - bmpNeedle.Height; outerY++)
{
for (int innerX = 0; innerX < bmpNeedle.Width; innerX++)
{
for (int innerY = 0; innerY < bmpNeedle.Height; innerY++)
{
Color cNeedle = bmpNeedle.GetPixel(innerX, innerY);
Color cHaystack = bmpHaystack.GetPixel(innerX + outerX, innerY + outerY);

if (cNeedle.R != cHaystack.R || cNeedle.G != cHaystack.G || cNeedle.B != cHaystack.B)
{
goto notFound;
}
}
}
location = new Point(outerX, outerY);
listBox1.Items.Add(location);
MessageBox.Show(location.ToString());
notFound:
continue;
}
}

}
catch (Exception)
{

}
location = Point.Empty;
return false;
}

最佳答案

I want to the program to bring me all the results not just one result

返回所有结果的列表。因此,您将修改您的方法以具有不同的返回类型:

public List<Point> FindBitmap(Bitmap bmpNeedle, Bitmap bmpHaystack, out Point location)
{
List<Point> results = new List<Point>();

for (int outerX = 0; outerX < bmpHaystack.Width - bmpNeedle.Width; outerX++)
{
for (int outerY = 0; outerY < bmpHaystack.Height - bmpNeedle.Height; outerY++)
{
for (int innerX = 0; innerX < bmpNeedle.Width; innerX++)
{
for (int innerY = 0; innerY < bmpNeedle.Height; innerY++)
{
Color cNeedle = bmpNeedle.GetPixel(innerX, innerY);
Color cHaystack = bmpHaystack.GetPixel(innerX + outerX, innerY + outerY);
if (cNeedle.R != cHaystack.R || cNeedle.G != cHaystack.G || cNeedle.B != cHaystack.B)
{
goto notFound;
}
}
}
location = new Point(outerX, outerY);
// collect the result
results.Add(location);
notFound:
continue;
}
}

// when you are finished looping return it
return results;

}

关于C#颜色检测多于一个结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42506220/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com