AutoIt ImageSearch2015 and transparency menu

Shout-Out

User Tag List

Results 1 to 1 of 1
  1. #1
    kornboy82's Avatar Member
    Reputation
    7
    Join Date
    Jun 2014
    Posts
    23
    Thanks G/R
    0/6
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    AutoIt ImageSearch2015 and transparency

    Does anybody here have experience with the ImageSearchDLL and AutoIt?

    I'm trying to program a bot that will find numbers on the screen. The background behind the numbers is always changing so to be able to make it work in the way it should, I need to use transparency to make it ignore some parts of the reference image I'm using.

    For example, the following code I use is working when I remove tranparency. It finds the not modified BPM without problems.When I add transparency color, the mouse always moves in the top corner at the same coordinates everytime.

    Code:
       $results = _ImageSearch("base.bmp",1, $FoundX,$FoundY,50,0xFF00FF)
       If ($results = 1) Then
    	  ConsoleWrite("Found Image" & @CRLF)
    	  mousemove($FoundX, $FoundY)
       EndIf
    Just for your information, the game I'm doing this is inside Bluestacks emulator. Maybe a memory read method would work but I'm not enough advanced in this kind of programming. My bot is overall working for Dissidia Opera Omnia but for features I want to add, transparency is needed.

    Here is the ImageSearch.au3 script. It's linked to some DLLs that I won't join here because overall, my things are working except the transparency.

    Thanks

    Code:
    #AutoIt3Wrapper_UseX64=y ; Set to Y or N depending on your situation/preference!!
    #include-once
    #include <WinAPIFiles.au3> ; for _WinAPI_Wow64EnableWow64FsRedirection
    #include <ScreenCapture.au3> ;_ScreenCapture_CaptureWnd etc. ;using this in the example to create a test image, otherwise not neccessary here
    
    #Region When running compiled script, Install needed DLLs if they don't exist yet
    If Not FileExists("ImageSearchDLLx32.dll") Then FileInstall("ImageSearchDLLx32.dll", "ImageSearchDLLx32.dll", 1);FileInstall ( "source", "dest" [, flag = 0] )
    If Not FileExists("ImageSearchDLLx64.dll") Then FileInstall("ImageSearchDLLx64.dll", "ImageSearchDLLx64.dll", 1)
    If Not FileExists("msvcr110d.dll") Then FileInstall("msvcr110d.dll", "msvcr110d.dll", 1);Microsoft Visual C++ Redistributable dll x64
    If Not FileExists("msvcr110.dll") Then FileInstall("msvcr110.dll", "msvcr110.dll", 1);Microsoft Visual C++ Redistributable dll x32
    #EndRegion
    
    Local $h_ImageSearchDLL = -1; Will become Handle returned by DllOpen() that will be referenced in the _ImageSearchRegion() function
    
    #Region ImageSearch Startup/Shutdown
    Func _ImageSearchStartup()
    	_WinAPI_Wow64EnableWow64FsRedirection(True)
    	$sOSArch = @OSArch ;Check if running on x64 or x32 Windows ;@OSArch Returns one of the following: "X86", "IA64", "X64" - this is the architecture type of the currently running operating system.
    	$sAutoItX64 = @AutoItX64 ;Check if using x64 AutoIt ;@AutoItX64 Returns 1 if the script is running under the native x64 version of AutoIt.
    	If $sOSArch = "X86" Or $sAutoItX64 = 0 Then
    		$h_ImageSearchDLL = DllOpen("ImageSearchDLLx32.dll")
    		If $h_ImageSearchDLL = -1 Then Return "DllOpen failure"
    	ElseIf $sOSArch = "X64" And $sAutoItX64 = 1 Then
    		$h_ImageSearchDLL = DllOpen("ImageSearchDLLx64.dll")
    		If $h_ImageSearchDLL = -1 Then Return "DllOpen failure"
    	Else
    		Return "Inconsistent or incompatible Script/Windows/CPU Architecture"
    	EndIf
    	Return True
    EndFunc   ;==>_ImageSearchStartup
    
    Func _ImageSearchShutdown()
    	DllClose($h_ImageSearchDLL)
    	_WinAPI_Wow64EnableWow64FsRedirection(False)
    	Return True
    EndFunc   ;==>_ImageSearchShutdown
    #EndRegion ImageSearch Startup/Shutdown
    
    #Region ImageSearch UDF;slightly modified
    ; ------------------------------------------------------------------------------
    ;
    ; 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
    ;                   $transparency - TRANSBLACK, TRANSWHITE or hex value (e.g. 0xffffff) of
    ;                                  the color to be used as transparency; can be omitted if
    ;                                  not needed
    ;
    ; Return Value(s):  On Success - Returns True
    ;                   On Failure - Returns False
    ;
    ; 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, $transparency = 0)
    	Return _ImageSearchArea($findImage, $resultPosition, 0, 0, @DesktopWidth, @DesktopHeight, $x, $y, $tolerance, $transparency)
    EndFunc   ;==>_ImageSearch
    
    Func _ImageSearchArea($findImage, $resultPosition, $x1, $y1, $right, $bottom, ByRef $x, ByRef $y, $tolerance = 0, $transparency = 0);Credits to Sven for the Transparency addition
    	If Not FileExists($findImage) Then Return "Image File not found"
    	If $tolerance < 0 Or $tolerance > 255 Then $tolerance = 0
    	If $h_ImageSearchDLL = -1 Then _ImageSearchStartup()
    
    	If $transparency <> 0 Then $findImage = "*" & $transparency & " " & $findImage
    	If $tolerance > 0 Then $findImage = "*" & $tolerance & " " & $findImage
    	$result = DllCall($h_ImageSearchDLL, "str", "ImageSearch", "int", $x1, "int", $y1, "int", $right, "int", $bottom, "str", $findImage)
    
    	If @error Then
    	ConsoleWrite("DllCall Error=" & @error)
    		Return 0
    	EndIf
    
    	If Not IsArray($result) Or $result = 0 Then Return 0
    	If $result[0] = "0" Then Return 0
    
    	$array = StringSplit($result[0], "|")
    	If (UBound($array) >= 4) Then
    		$x = Int(Number($array[2])); Get the x,y location of the match
    		$y = Int(Number($array[3]))
    		If $resultPosition = 1 Then
    			$x = $x + Int(Number($array[4]) / 2); Account for the size of the image to compute the centre of search
    			$y = $y + Int(Number($array[5]) / 2)
    		EndIf
    		Return 1
    	EndIf
    EndFunc   ;==>_ImageSearchArea
    
    ;===============================================================================
    ;
    ; Description:      Wait for a specified number of seconds for an image to appear
    ;
    ; Syntax:           _WaitForImageSearch, _WaitForImagesSearch
    ; Parameter(s):
    ;                   $waitSecs  - seconds to try and find the image
    ;                   $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
    ;                   $transparency - TRANSBLACK, TRANSWHITE or hex value (e.g. 0xffffff) of
    ;                                  the color to be used as transparency can be omitted if
    ;                                  not needed
    ;
    ; Return Value(s):  On Success - Returns 1
    ;                   On Failure - Returns 0
    ;
    ;
    ;===============================================================================
    Func _WaitForImageSearch($findImage, $waitSecs, $resultPosition, ByRef $x, ByRef $y, $tolerance, $transparency = 0)
    	$waitSecs = $waitSecs * 1000
    	$startTime = TimerInit()
    	While TimerDiff($startTime) < $waitSecs
    		Sleep(100)
    		If _ImageSearch($findImage, $resultPosition, $x, $y, $tolerance, $transparency) Then
    			Return True
    		EndIf
    	WEnd
    	Return False
    EndFunc   ;==>_WaitForImageSearch
    
    ;===============================================================================
    ;
    ; Description:      Wait for a specified number of seconds for any of a set of
    ;                   images to appear
    ;
    ; Syntax:           _WaitForImagesSearch
    ; Parameter(s):
    ;                   $waitSecs  - seconds to try and find the image
    ;                   $findImage - the ARRAY of images to locate on the desktop
    ;                              - ARRAY[0] is set to the number of images to loop through
    ;                                ARRAY[1] is the first image
    ;                   $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
    ;                   $transparent - TRANSBLACK, TRANSWHITE or hex value (e.g. 0xffffff) of
    ;                                  the color to be used as transparent; can be omitted if
    ;                                  not needed
    ;
    ; Return Value(s):  On Success - Returns the index of the successful find
    ;                   On Failure - Returns 0
    ;
    ;
    ;===============================================================================
    Func _WaitForImagesSearch($findImage, $waitSecs, $resultPosition, ByRef $x, ByRef $y, $tolerance, $transparency = 0)
    	$waitSecs = $waitSecs * 1000
    	$startTime = TimerInit()
    	While TimerDiff($startTime) < $waitSecs
    		For $i = 1 To $findImage[0]
    			Sleep(100)
    			If _ImageSearch($findImage[$i], $resultPosition, $x, $y, $tolerance, $transparency) Then
    				Return $i
    			EndIf
    		Next
    	WEnd
    	Return False
    EndFunc   ;==>_WaitForImagesSearch
    #EndRegion ImageSearch UDF;slightly modified

    AutoIt ImageSearch2015 and transparency

Similar Threads

  1. looking to learn some c c++ c# autoit php and html and xml
    By JDBSOGTFO in forum WoW Bots Questions & Requests
    Replies: 0
    Last Post: 11-12-2012, 11:40 PM
  2. Autoit broadcasting and multiboxing
    By Halfshey297 in forum WoW Bots Questions & Requests
    Replies: 2
    Last Post: 08-12-2012, 05:28 PM
  3. [Guide] Transparency and Size
    By reflex0rzor in forum WoW ME Tools & Guides
    Replies: 24
    Last Post: 07-06-2010, 01:28 PM
All times are GMT -5. The time now is 08:24 PM. Powered by vBulletin® Version 4.2.3
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved. User Alert System provided by Advanced User Tagging (Pro) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
Google Authenticator verification provided by Two-Factor Authentication (Free) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
Digital Point modules: Sphinx-based search