Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Java中使用ImageSearchDll.dll(来自AutoIt)编辑:JNA_Java_Dll_Import_Jna_Autoit - Fatal编程技术网

在Java中使用ImageSearchDll.dll(来自AutoIt)编辑:JNA

在Java中使用ImageSearchDll.dll(来自AutoIt)编辑:JNA,java,dll,import,jna,autoit,Java,Dll,Import,Jna,Autoit,我想在Java程序中对屏幕事件做出反应,因此我想在实际屏幕中找到一个图像。我试图编写一个方法,从robot类中获取一个屏幕截图,然后搜索像素——但这需要很长时间 我知道在AutoIt中有一个外部DLL可以很好地完成这项工作,现在我尝试让它在java中运行。。。但我被卡住了:/ .dll是在自动模式中调用的,它包括以下内容: Func _ImageSearch($findImage,$resultPosition,ByRef $x, ByRef $y,$tolerance) return _

我想在Java程序中对屏幕事件做出反应,因此我想在实际屏幕中找到一个图像。我试图编写一个方法,从robot类中获取一个屏幕截图,然后搜索像素——但这需要很长时间

我知道在AutoIt中有一个外部DLL可以很好地完成这项工作,现在我尝试让它在java中运行。。。但我被卡住了:/

.dll是在自动模式中调用的,它包括以下内容:

Func _ImageSearch($findImage,$resultPosition,ByRef $x, ByRef $y,$tolerance)
   return _ImageSearchArea($findImage,$resultPosition,0,0,@DesktopWidth,@DesktopHeight,$x,$y,$tolerance)
EndFunc
static {
    File file = new File("libs", "ImageSearchDLL.dll");
    System.load(file.getAbsolutePath());
    }
(...)
String a = ImageSearchDLL.INSTANCE.ImageSearch(0, 0, 500, 500, "C:\myProg\OK.bmp");
以及:

我得到了dll,并尝试了类似jna的东西,但我无法让它工作。我还尝试了AutoItX,以使AutoIt函数在Java中运行,但它不适用于includes。你能帮我吗

编辑:好的,我在JNA上做了另一次尝试,现在我得到了一个字符串——但是这个字符串意味着错误。有什么问题吗? 我有一个界面:

public interface ImageSearchDLL extends Library{
ImageSearchDLL INSTANCE = (ImageSearchDLL) Native.loadLibrary("ImageSearchDLL", ImageSearchDLL.class);
String ImageSearch(int x1, int y1, int x2, int y2, String findImage);   
}
我这样称呼它:

Func _ImageSearch($findImage,$resultPosition,ByRef $x, ByRef $y,$tolerance)
   return _ImageSearchArea($findImage,$resultPosition,0,0,@DesktopWidth,@DesktopHeight,$x,$y,$tolerance)
EndFunc
static {
    File file = new File("libs", "ImageSearchDLL.dll");
    System.load(file.getAbsolutePath());
    }
(...)
String a = ImageSearchDLL.INSTANCE.ImageSearch(0, 0, 500, 500, "C:\myProg\OK.bmp");
我总是将“0”返回到表示错误或未找到的位置,就像我在AutoIT文件中看到的那样:

; If error exit
if $result[0]="0" then return 0

您能帮我解决这个问题吗?

您选择的另一种方法是使用
Runtime.getRuntime().exec()
生成一个应用程序(c、autoit脚本等),该应用程序执行图像搜索并使用基于文件的/轮询方法(或通过标准输出)用于它们之间的通信,以便将结果发送到java应用程序。

您是否有一个用于您尝试调用的函数的实际原型(最好是C)?原始的_ImageSearchArea函数中的“ByRef”修饰符似乎暗示ImageSearch期望这些参数为
int*
,而不是
int
。JNA中对应的类型是
IntByReference