简体   繁体   English

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

[英]Use ImageSearchDll.dll in Java ( from AutoIt ) edit: JNA

I want to react on a screen event in my Java Programm so i want to find a Image in my actual screen. 我想对我的Java程序中的屏幕事件做出反应,所以我想在实际屏幕中找到一个图像。 I tried to write a method to get a Screenshot from the robot class and then search the pixels - but it took way to long. 我试着编写一个方法来从机器人类中获取一个截图,然后搜索像素 - 但它已经过了很长时间。

I know that in AutoIt there is a external DLL that does this job pretty good and now i tried to get it running in java... But i am stuck :/ 我知道在AutoIt中有一个外部DLL可以很好地完成这项工作,现在我试着让它在java中运行......但是我被卡住了:/

The .dll is called in the AutoIt Includes like this: .Ill在AutoIt中调用包括如下:

Func _ImageSearch($findImage,$resultPosition,ByRef $x, ByRef $y,$tolerance)
   return _ImageSearchArea($findImage,$resultPosition,0,0,@DesktopWidth,@DesktopHeight,$x,$y,$tolerance)
EndFunc

and: 和:

Func _ImageSearchArea($findImage,$resultPosition,$x1,$y1,$right,$bottom,ByRef $x, ByRef $y, $tolerance)

if $tolerance>0 then $findImage = "*" & $tolerance & " " & $findImage
$result = DllCall("ImageSearchDLL.dll","str","ImageSearch","int",$x1,"int",$y1,"int",$right,"int",$bottom,"str",$findImage)

if $result[0]="0" then return 0

$array = StringSplit($result[0],"|")

$x=Int(Number($array[2]))
$y=Int(Number($array[3]))
if $resultPosition=1 then
  $x=$x + Int(Number($array[4])/2)
  $y=$y + Int(Number($array[5])/2)
endif
return 1
EndFunc

I got the dll and tried things like jna but i can't get it working. 我得到了dll并尝试了像jna这样的东西,但我无法让它工作。 I also tried AutoItX to get AutoIt Functions running in Java but it doesn't work with includes. 我还尝试使用AutoItX来使用Java运行AutoIt函数,但它不能用于包含。 Can you help me? 你能帮助我吗?

edit: Ok i did another try on JNA and now i get a String back - but the String means error. 编辑:好的我在JNA上做了另一次尝试,现在我得到了一个String - 但是String意味着错误。 Whats the problem? 有什么问题? I have a Interface: 我有一个界面:

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);   
}

and i call it like this: 我称之为:

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");

I always get "0" back where means Error or not found like i can see in the AutoIT file: 我总是得到“0”返回意味着错误或找不到像我在AutoIT文件中看到的那样:

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

Can you help me fix that? 你能帮我解决这个问题吗?

您正在使用的路径的另一种方法是使用Runtime.getRuntime().exec()来生成执行imagesearch并使用基于文件/轮询方法(或通过标准输出)的应用程序(c,自动脚本等)它们之间的通信将您的结果提供给您的Java应用程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM