Mbee Posted September 15, 2019 Share Posted September 15, 2019 (edited) So I've been able to use some version of ImageSearch.au3 (author unknown) and some version of ImageSearchDLL.dll in the past, but trying again now I find I am very confused. First, which set should I choose? Here's the header and some code from the first part of the version of ImageSearch.au3 I have, in case anyone can identify it... expandcollapse popup#include-once ; ------------------------------------------------------------------------------ ; ; AutoIt Version: 3.0 ; Language: English ; Description: Functions that assist with Image Search ; Require that the ImageSearchDLL.dll be loadable ; ; ------------------------------------------------------------------------------ ;=============================================================================== ; ; Description: Find the position of an image on the desktop ; Syntax: _ImageSearchArea, _ImageSearch ; Parameter(s): ; $findImage - the image to locate on the desktop ; $tolerance - 0 for no tolerance (0-255). Needed when colors of ; image differ from desktop. e.g GIF ; $resultPosition - Set where the returned x,y location of the image is. ; 1 for centre of image, 0 for top left of image ; $x $y - Return the x and y location of the image ; ; Return Value(s): On Success - Returns 1 ; On Failure - Returns 0 ; ; Note: Use _ImageSearch to search the entire desktop, _ImageSearchArea to specify ; a desktop region to search ; ;=============================================================================== Func _ImageSearch($findImage, $resultPosition, ByRef $x, ByRef $y,$tolerance, $HBMP=0) return _ImageSearchArea($findImage,$resultPosition,0,0,@DesktopWidth,@DesktopHeight,$x,$y,$tolerance,$HBMP) EndFunc Func _ImageSearchArea($findImage, $resultPosition, $x1, $y1, $arg_right, $bottom, ByRef $x, ByRef $y, $tolerance, $HBMP=0) ;MsgBox(0,"asd","" & $x1 & " " & $y1 & " " & $right & " " & $bottom) if $tolerance>0 then $findImage = "*" & $tolerance & " " & $findImage Local $right = $arg_right If IsString($findImage) Then Local $result = DllCall("ImageSearchDLL.dll", "str", "ImageSearch", "int", $x1, "int", $y1, "int", $right, "int", $bottom, "str", $findImage, "ptr", $HBMP) Else Local $result = DllCall("ImageSearchDLL.dll", "str", "ImageSearch", "int", $x1, "int", $y1, "int", $right, "int", $bottom, "ptr", $findImage, "ptr", $HBMP) EndIf ; If error exit if $result[0]="0" then return 0 ; Otherwise get the x,y location of the match and the size of the image to ; compute the centre of search Local $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 My problem is with the error return processing ("if $result[0]="0" then return 0"), which causes the latest version of AutoIt x64 to complain that the $result variable is not an array / subscript invalid. My hunch is that the .au3 file and the .dll are not compatible, but I don't know what to do about it. My need is to to see if a particular area within a desktop window looks like scenario 1 or scenario 2. Would someone be able to help me, please? Edited September 15, 2019 by Mbee Link to comment Share on other sites More sharing options...
mistersquirrle Posted September 16, 2019 Share Posted September 16, 2019 (edited) I've used this as well, and I know that I've found several versions, so the easiest thing to do is provide what I've been using (attached). I mainly have used the _ImageSearchArea part, with transparency, and a call with it for me usually looks like this: Local $sFile = 'image.png' ; Path to the image file, we dont need to open it or get a handle or anything first Local $aRange[] = [4, 100, 100, 300, 300] ; Area to search, x1, y1, x2, y2 Local $aCoords[2] ; Resulting location of the found image, either top left or center of image based on second parameter Local $iShade = 10 ; 10 'shades' of variance, useful if the image is saved with compression, for example Local $sTrans = "0xFF0000" ; Red in the image is 'transparent', and isnt used in the image comparison. Useful if a section of the image could be different on each check Local $bIS $bIS = _ImageSearchArea($sFile, 1, $aRange[1], $aRange[2], $aRange[3], $aRange[4], $aCoords[0], $aCoords[1], $iShade, $sTrans) If $bIS Then ; Do the thing EndIf I currently use this in Windows 10 without a problem, and I believe that it's run as 32 bit, so not sure how the 64 bit performs. I haven't really ever had any issues with using it. Let me know if you want more of an explanation or full example. ImageSearch files.zip Edited September 16, 2019 by mistersquirrle Mbee 1 We ought not to misbehave, but we should look as though we could. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now