如何解决C# 使用 ImageSearch DLL 进行图像搜索
在我当前的项目中,我需要一种将图像与源图像进行比较的方法。 此函数由 ImageSearch DLL 提供。
已经有关于此主题的帖子:
我已经在这些帖子中提供的帮助下成功地使用了 ImageSearch 并对其进行了一些修改,如下面的代码所示。
一切似乎都运行良好,但与“C# ImageSearch DLL”中的 @Moshisho 和 @Matt Woodruff 不同, data[2] 确实返回 y1 INPUT 而不是它应该返回的左上角的 y 坐标。 不过,x1 确实返回了正确的值。
看到他交了
IntPtr result = ImageSearch(0,1920,1080,imgPath);
Console.WriteLine(data[1] + "," + data[2]);
他得到 1849,53 而我得到 1849,0
我希望您能弄清楚为什么我会收到不同的值 - 在此先感谢您的帮助!
可以找到有关 ImageSearch DLL 的更多详细信息here
string filename = (@"C:\temp\ImgName.png");
string[] ImageResult = ImgSearch.UseImageSearch(filename,"120",-1920,940,-1375,1080);
public static class ImgSearch {
[DllImport(@"C:\ImageSearchDLL.dll")]
static extern IntPtr ImageSearch(int x,int y,int right,int bottom,[MarshalAs(UnmanagedType.LPStr)] string imagePath);
public static String[] UseImageSearch(string IMGPath,string tolerance,int x1 = -1920,int y1 = 270,int x2 = 1920,int y2 = 540) {
IMGPath = "*" + tolerance + " " + IMGPath;
IntPtr result;
if(MainWindow.CurrentHostName == "DiffrentHosteName") { //1 Screen
x1 += 1920;
x2 += 1920;
result = ImageSearch(x1,y1,x2,y2,IMGPath);
}
else {
result = ImageSearch(x1,IMGPath); //2 Screens (PrimaryScreen is the right one)
}
String res = Marshal.PtrToStringAnsi(result);
if(res[0] == '0') return null;
String[] data = res.Split('|');
//0->found,1->x,2->y,3->image width,4->image height;
// Then,you can parse it to get x and y:
int x; int y;
int.TryParse(data[1],out x);
int.TryParse(data[2],out y);
return data;
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。