【发布时间】:2020-02-08 20:15:19
【问题描述】:
我正在尝试将 AutoIt 中的 DLL 与 C# (ImageSearch) 一起使用
DLL 用于检测屏幕上的给定图像
这是我的代码:
[DllImport("ImageSearchDLL.dll")]
private static extern IntPtr ImageSearch(int x, int y, int right, int bottom, [MarshalAs(UnmanagedType.LPStr)]string imagePath);
public static String[] UseImageSearch(string imgPath)
{
int right = Screen.PrimaryScreen.WorkingArea.Right;
int bottom = Screen.PrimaryScreen.WorkingArea.Bottom;
IntPtr result = ImageSearch(0, 0, right, bottom, imgPath);
String res = Marshal.PtrToStringAnsi(result);
if (res[0] == '0') return null;//not found
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;
}
所以,在这一行调用 ImageSearch 函数时,我得到了 System.BadImageFormatException:
IntPtr result = ImageSearch(0, 0, right, bottom, imgPath);
有什么想法吗?非常感谢
【问题讨论】:
-
AutoIt
ImageSearch函数有以下参数:ImageSearch("patterntosearch",where,x,y,tolerance),其中patterntosearch是文件名(bmp或png),where是0或1(返回中点或左上角)角)和tolerance,一个介于0(完全匹配)和255(?不确定)之间的值,以接受一些颜色偏移。x和y接收找到的位置。
标签: c# autoit-c#-wrapper