Sign in to follow this  
Followers 0

myImageSearch


12 posts in this topic

Posted

description: search image in desktop / picture.

not require dll. :D

include: myImageSearch.au3

#include-once
#include <ScreenCapture.au3>
 
; #INDEX# =======================================================================================================================
; Title .........: myImageSearch
; AutoIt Version: 3.3.6.1
; Script Version: 1.0 (31.10.2011)
; Language: English, Polski.
; Description: Search image.
; ===============================================================================================================================
 
 
; #CURRENT# =====================================================================================================================
; myImageSearch_Desktop
; myImageSearch_Picture
; ===============================================================================================================================
 
 
; #FUNCTION# ====================================================================================================================
; Name...........: myImageSearch_Desktop
; Description ...: Znajdz obrazek na pulpicie.
; Syntax.........: myImageSearch_Desktop($Image, $x = 0, $y = 0, $iIW = @DesktopWidth, $iIH = @DesktopHeight, $TransColorRGB = '', $OnlyFirst = True)
; Parameters ....: $Image - znajdz obrazek: adres do szuaknego obrazka, lub bitmapa (format .bmp 24-bit)
; $x - lewe koordynaty [Default is 0 (pierwszy pixel).]
; $y - gorne koordynaty. [Default is 0 (pierwszy pixel).]
; $iIW - prawe koordynaty. [Default is @DesktopWidth.]
; $iIH - dolne koordynaty. [Default is @DesktopHeight.]
; $TransColorRGB - Kolor przezroczystosci / Ignorowany kolor. Musi byc string i format RGB. a.g: "0xFFFFFF".[Default is "".]
; $OnlyFirst - [Default is True.]
; |True = Success: Zwraca tablice 2-elementowa z koordynatami.
; $array[0] = x koordynaty
; $array[1] = y koordynaty
; |False = Success: Zwraca 2D tablice z koordynatami.
; $array[0][0] = 1st x coordinate
; $array[0][1] = 1st y coordinate
; $array[1][0] = 2nd x coordinate
; $array[1][1] = 2nd y coordinate
; $array[3][0] = 3rd x coordinate
; $array[3][1] = 3rd y coordinate
; $array[n][0] = nth x coordinate
; $array[n][1] = nth y coordinate
;
; UWAGA: Jesli uzyjesz "False" to max obszar przeszukiwania moze wynosic 800x600 pixeli, lub ekwiwalent max 480.000 pixeli!!!
; Nie wiecej.
;
; Return values . : On Success - Zwrot tablica 2-elementowa z koordynatami lub 2D tablica z koordynatami.
; On Failure - @Error = 1 - Sciezka do pliku jest bledna, lub bitmapa/obrazek jest bledna.
; @Error = 2 - Obrazka nie znaleziono (na pulpicie).
; ===============================================================================================================================
 
 
; #FUNCTION# ====================================================================================================================
; Name...........: myImageSearch_Desktop
; Description ...: Image search in desktop.
; Syntax.........: myImageSearch_Desktop($Image, $x = 0, $y = 0, $iIW = @DesktopWidth, $iIH = @DesktopHeight, $TransColorRGB = '', $OnlyFirst = True)
; Parameters ....: $Image - search image: string adress for file, or bitmat (format .bmp 24-bit)
; $x - left coordinate. [Default is 0 (first pixel).]
; $y - top coordinate. [Default is 0 (first pixel).]
; $iIW - right coordinate. [Default is @DesktopWidth.]
; $iIH - bottom coordinate. [Default is @DesktopHeight.]
; $TransColorRGB - Color transparancy / Ignore color. Must be string and format RGB. a.g: "0xFFFFFF".[Default is "".]
; $OnlyFirst - [Default is True.]
; |True = Success: Returns a two-element array coordinates.
; $array[0] = x coordinate
; $array[1] = y coordinate
; |False = Success: Returns a 2D array coordinates.
; $array[0][0] = 1st x coordinate
; $array[0][1] = 1st y coordinate
; $array[1][0] = 2nd x coordinate
; $array[1][1] = 2nd y coordinate
; $array[3][0] = 3rd x coordinate
; $array[3][1] = 3rd y coordinate
; $array[n][0] = nth x coordinate
; $array[n][1] = nth y coordinate
;
; ATTENTION: If u use "False" max area for search must be 800x600 pixels, or equivalent maximal 480.000 pixels!!!
; No more.
;
; Return values . : On Success - Returns two-element array coordinates, or 2D array coordinates.
; On Failure - @Error = 1 - Path not found or invalid image/bitmap.
; @Error = 2 - Image not exist (in desktop).
; ===============================================================================================================================
 
 
Func myImageSearch_Desktop($Image, $x = 0, $y = 0, $iIW = @DesktopWidth, $iIH = @DesktopHeight, $TransColorRGB = '', $OnlyFirst = True)
Local $hBMP, $hImage1, $aReturn, $error, $i
_GDIPlus_Startup()
$hBMP = _ScreenCapture_Capture("", $x, $y, $iIW + $x, $iIH + $y, False)
$hImage1 = _GDIPlus_BitmapCreateFromHBITMAP($hBMP)
$aReturn = myImageSearch_Picture($hImage1, $Image, 0, 0, $iIW, $iIH, $TransColorRGB, $OnlyFirst)
$error = @error
_GDIPlus_ImageDispose($hImage1)
_WinAPI_DeleteObject($hBMP)
_GDIPlus_Shutdown()
 
Switch $error
Case 0
If $OnlyFirst Then
$aReturn[0] += $x
$aReturn[1] += $y
Else
For $i = 0 To UBound($aReturn, 1) - 1
$aReturn[$i][0] += $x
$aReturn[$i][1] += $y
Next
EndIf
Return $aReturn
Case 2
Return SetError(1, 1, '')
Case Else
Return SetError(2, 2, '')
EndSwitch
 
EndFunc ;==>myImageSearch_Desktop
 
 
; #FUNCTION# ====================================================================================================================
; Name...........: myImageSearch_Picture
; Description ...: Znajdz obrazek na obrazku.
; Syntax.........: myImageSearch_Picture($hImage1, $hImage2, $x = 0, $y = 0, $iIW = 0, $iIH = 0, $TransColorRGB = '', $OnlyFirst = True)
; Parameters ....: $hImage1 - bazowy obrazek: adres do szuaknego obrazka, lub bitmapa (format .bmp 24-bit)
; $hImage2 - znajdz obrazek: adres do szuaknego obrazka, lub bitmapa (format .bmp 24-bit)
; $x - lewe koordynaty [Default is 0 (pierwszy pixel).]
; $y - gorne koordynaty. [Default is 0 (pierwszy pixel).]
; $iIW - prawe koordynaty. [Default is 0 (0 to ostani pixel (caly obrazek).]
; $iIH - dolne koordynaty. [Default is 0 (0 to ostani pixel (caly obrazek).]
; $TransColorRGB - Kolor przezroczystosci / Ignorowany kolor. Musi byc string i format RGB. a.g: "0xFFFFFF".[Default is "".]
; $OnlyFirst - [Default is True.]
; |True = Success: Zwraca tablice 2-elementowa z koordynatami.
; $array[0] = x koordynaty
; $array[1] = y koordynaty
; |False = Success: Zwraca 2D tablice z koordynatami.
; $array[0][0] = 1st x coordinate
; $array[0][1] = 1st y coordinate
; $array[1][0] = 2nd x coordinate
; $array[1][1] = 2nd y coordinate
; $array[3][0] = 3rd x coordinate
; $array[3][1] = 3rd y coordinate
; $array[n][0] = nth x coordinate
; $array[n][1] = nth y coordinate
;
; UWAGA: Jesli uzyjesz "False" to max obszar przeszukiwania moze wynosic 800x600 pixeli, lub ekwiwalent max 480.000 pixeli!!!
; Nie wiecej.
;
; Return values . : On Success - Zwrot tablica 2-elementowa z koordynatami lub 2D tablica z koordynatami.
; On Failure - @Error = 1 - 1 sciezka do pliku jest bledna, lub bitmapa/obrazek jest bledna.
; @Error = 2 - 2 sciezka do pliku jest bledna, lub bitmapa/obrazek jest bledna.
; @Error = 3 - Obrazka nie znaleziono (na obrazku).
; ===============================================================================================================================
 
 
; #FUNCTION# ====================================================================================================================
; Name...........: myImageSearch_Picture
; Description ...: Image search in picture.
; Syntax.........: myImageSearch_Picture($hImage1, $hImage2, $x = 0, $y = 0, $iIW = 0, $iIH = 0, $TransColorRGB = '', $OnlyFirst = True)
; Parameters ....: $hImage1 - base image: string adress for file, or bitmat (format .bmp 24-bit)
; $hImage2 - search image: string adress for file, or bitmat (format .bmp 24-bit)
; $x - left coordinate. [Default is 0 (first pixel).]
; $y - top coordinate. [Default is 0 (first pixel).]
; $iIW - right coordinate. [Default is 0 (0 is last pixel (full imege).]
; $iIH - bottom coordinate. [Default is 0 (0 is last pixel (full imege).]
; $TransColorRGB - Color transparancy / Ignore color. Must be string and format RGB. a.g: "0xFFFFFF".[Default is "".]
; $OnlyFirst - [Default is True.]
; |True = Success: Returns a two-element array coordinates.
; $array[0] = x coordinate
; $array[1] = y coordinate
; |False = Success: Returns a 2D array coordinates.
; $array[0][0] = 1st x coordinate
; $array[0][1] = 1st y coordinate
; $array[1][0] = 2nd x coordinate
; $array[1][1] = 2nd y coordinate
; $array[3][0] = 3rd x coordinate
; $array[3][1] = 3rd y coordinate
; $array[n][0] = nth x coordinate
; $array[n][1] = nth y coordinate
;
; ATTENTION: If u use "False" max area for search must be 800x600 pixels, or equivalent maximal 480.000 pixels!!!
; No more.
;
; Return values . : On Success - Returns two-element array coordinates, or 2D array coordinates.
; On Failure - @Error = 1 - 1st path not found or invalid image/bitmap.
; @Error = 2 - 2nd path not found or invalid image/bitmap.
; @Error = 3 - Image not exist (in picture).
; ===============================================================================================================================
 
 
Func myImageSearch_Picture($hImage1, $hImage2, $x = 0, $y = 0, $iIW = 0, $iIH = 0, $TransColorRGB = '', $OnlyFirst = True)
Local $testiIW, $testiIH
Local $hBitmap1, $Reslt, $width, $height, $stride, $format, $Scan0
Local $iIW_2, $iIH_2, $hBitmap2, $Reslt2, $width2, $height2, $stride2, $format2, $Scan02
Local $sREResult1, $sREResult2, $sREResult3
 
_GDIPlus_Startup()
 
If IsString($hImage1) Then
$hImage1 = _GDIPlus_ImageLoadFromFile($hImage1)
EndIf
 
$testiIW = _GDIPlus_ImageGetWidth($hImage1)
$testiIH = _GDIPlus_ImageGetHeight($hImage1)
 
If $hImage2 = "" Or $testiIW = 0 Or $testiIH = 0 Then
Return SetError(1, 1, '')
EndIf
 
If $iIW = 0 Or $testiIW < $iIW Then $iIW = $testiIW
If $iIH = 0 Or $testiIH < $iIH Then $iIH = $testiIH
 
$hBitmap1 = _GDIPlus_BitmapCloneArea($hImage1, 0, 0, $iIW, $iIH, $GDIP_PXF32ARGB)
$Reslt = _GDIPlus_BitmapLockBits($hBitmap1, $x, $y, $iIW - $x, $iIH - $y, BitOR($GDIP_ILMREAD, $GDIP_ILMWRITE), $GDIP_PXF32ARGB)
$width = DllStructGetData($Reslt, "width")
$height = DllStructGetData($Reslt, "height")
$stride = DllStructGetData($Reslt, "stride")
$format = DllStructGetData($Reslt, "format")
$Scan0 = DllStructGetData($Reslt, "Scan0")
$sREResult1 = DllStructCreate("byte[" & $height * $width * 4 & "]", $Scan0); Create DLL structure for all pixels
$sREResult1 = DllStructGetData($sREResult1, 1)
_GDIPlus_BitmapUnlockBits($hBitmap1, $Reslt); releases the locked region
_GDIPlus_ImageDispose($hImage1)
_GDIPlus_ImageDispose($hBitmap1)
 
If IsString($hImage2) Then
$hImage2 = _GDIPlus_ImageLoadFromFile($hImage2)
EndIf
 
$iIW_2 = _GDIPlus_ImageGetWidth($hImage2)
$iIH_2 = _GDIPlus_ImageGetHeight($hImage2)
 
If $hImage2 = "" Or $iIW_2 = 0 Or $iIH_2 = 0 Then
Return SetError(2, 2, '')
EndIf
 
$hBitmap2 = _GDIPlus_BitmapCloneArea($hImage2, 0, 0, $iIW_2, $iIH_2, $GDIP_PXF32ARGB)
$Reslt2 = _GDIPlus_BitmapLockBits($hBitmap2, 0, 0, $iIW_2, $iIH_2, BitOR($GDIP_ILMREAD, $GDIP_ILMWRITE), $GDIP_PXF32ARGB)
$width2 = DllStructGetData($Reslt2, "width")
$height2 = DllStructGetData($Reslt2, "height")
$stride2 = DllStructGetData($Reslt2, "stride")
$format2 = DllStructGetData($Reslt2, "format")
$Scan02 = DllStructGetData($Reslt2, "Scan0")
$sREResult2 = DllStructCreate("byte[" & $height2 * $width2 * 4 & "]", $Scan02); Create DLL structure for all pixels
$sREResult2 = DllStructGetData($sREResult2, 1)
_GDIPlus_BitmapUnlockBits($hBitmap2, $Reslt2); releases the locked region
_GDIPlus_ImageDispose($hImage2)
_GDIPlus_ImageDispose($hBitmap2)
 
_GDIPlus_Shutdown()
 
$sREResult1 = StringTrimLeft($sREResult1, 2)
$sREResult2 = StringTrimLeft($sREResult2, 2)
 
If IsString($TransColorRGB) Then ; ignore color
$TransColorRGB = StringRegExpReplace($TransColorRGB, "0x(.{2})(.{2})(.{2})", "\3\2\1FF")
If $TransColorRGB Then
$sREResult2 = StringRegExpReplace($sREResult2, "(.{8})", "\1 ")
$sREResult2 = StringReplace($sREResult2, $TransColorRGB, "........")
$sREResult2 = StringReplace($sREResult2, " ", "")
EndIf
EndIf
;ConsoleWrite($sREResult2 & @CRLF)
 
$sREResult2 = StringRegExpReplace($sREResult2, "(.{" & $iIW_2 * 8 & "})", "\\Q\1\\E.\{" & ($iIW - $iIW_2) * 8 & "\}")
$sREResult2 = StringTrimRight($sREResult2, StringLen(($iIW - $iIW_2) * 8) + 3)
;ConsoleWrite($sREResult2 & @CRLF)
 
If $TransColorRGB Then
$sREResult2 = StringReplace($sREResult2, "........", "\E........\Q")
$sREResult2 = StringReplace($sREResult2, "\Q\E", "")
$sREResult2 = StringRegExpReplace($sREResult2, "([.}{\w]*)([\\].*[E])([.}{\w]*)", "\2") ; obcina kropki
EndIf
;ConsoleWrite($sREResult2 & @CRLF)
 
If $OnlyFirst Then
$sREResult2 = '(?i)(.*?)' & $sREResult2 & ".*"
;ConsoleWrite($sREResult2 & @CRLF)
 
$sREResult3 = StringRegExpReplace($sREResult1, $sREResult2, "\1") ; test pathern ("first")
 
If Not @extended Then Return SetError(3, 3, '') ; extendet zero to nie znaleziono nic
 
$sREResult3 = StringLen($sREResult3) / 8
Local $pozycja_Y = Int($sREResult3 / $iIW) + $y
Local $pozycja_X = Int($sREResult3 - $pozycja_Y * $iIW) + ($y * $iIW)
Local $aReturn[2] = [$pozycja_X, $pozycja_Y]
 
Else
 
$sREResult2 = '(?i)(.*?)(' & $sREResult2 & ".*?)" ; wersja dla wielu winikow
;ConsoleWrite($sREResult2 & @CRLF)
 
$sREResult3 = StringRegExp($sREResult1, $sREResult2, 3) ; test pathern ("mulit")
 
If @error Or Not IsArray($sREResult3) Then Return SetError(3, 3, '')
 
Local $ile = UBound($sREResult3)
Local $i
Local $aReturn[$ile / 2][2]
Local $sREResult4 = 0
Local $pozycja_Y
Local $pozycja_X
 
For $i = 0 To $ile - 1 Step 2
$sREResult4 += StringLen($sREResult3[$i]) / 8
If $i > 0 Then $sREResult4 += StringLen($sREResult3[$i + 1]) / 8
 
$pozycja_Y = Int($sREResult4 / $iIW) + $y
$pozycja_X = Int($sREResult4 - $pozycja_Y * $iIW) + ($y * $iIW)
$aReturn[$i / 2][0] = $pozycja_X
$aReturn[$i / 2][1] = $pozycja_Y
Next
 
EndIf
Return $aReturn
EndFunc ;==>myImageSearch_Picture

example:

#include <array.au3>
#include <myImageSearch.au3>
 
;Opt('MustDeclareVars', 1)
 
;########## test 1 Desktop ##########
 
Global $pozycja1
Global $time1
 
Global $ImageSearch = @ScriptDir & "\recycle.bmp"
Global $x = 0
Global $y = 0
Global $w = @DesktopWidth
Global $h = @DesktopHeight
Global $ColorTrans = ''
Global $mOnlyFirst = True
 
Sleep(10)
$time1 = TimerInit()
 
$pozycja1 = myImageSearch_Desktop($ImageSearch, $x, $y, $w, $h, $ColorTrans, $mOnlyFirst)
If @error Then ConsoleWrite("sorry image not exist" & @CRLF)
 
ConsoleWrite("time 1: " & TimerDiff($time1) / 1000 & ' sek.' & @CRLF)
 
If IsArray($pozycja1) Then
_ArrayDisplay($pozycja1)
EndIf
 
;##################################
 
;########## test 2 Scren ##########
 
Global $pozycja2
Global $time2
 
Global $ImageBazowe = @ScriptDir & "\where is wally.bmp"
Global $ImageSearch = @ScriptDir & "\wanted wally.bmp"
Global $x = 0
Global $y = 0
Global $w = 0
Global $h = 0
Global $ColorTrans = "0x00ffff"
Global $mOnlyFirst = False ;False = search more image, but not all..,
; ;If u use "False" max area for search must be 800x600 pixels,
; ;or equivalent maximal 480.000 pixels!!!
; ;No more.
; ;Recommended is "True"
Sleep(10)
$time2 = TimerInit()
 
$pozycja2 = myImageSearch_Picture($ImageBazowe, $ImageSearch, $x, $y, $w, $h, $ColorTrans, $mOnlyFirst)
If @error Then ConsoleWrite("sorry image not exist" & @CRLF)
 
ConsoleWrite("time 2: " & TimerDiff($time2) / 1000 & ' sek.' & @CRLF)
 
If IsArray($pozycja2) Then
_ArrayDisplay($pozycja2)
EndIf
 
;##################################

myImageSearch.au3

myImageSearch (Examples).au3

recycle.bmp

where is wally.bmp

wanted wally.bmp

tbodine88 and XabiK like this

Share this post


Link to post
Share on other sites



Posted

I wonder about the speed with the script vs. dll.

Share this post


Link to post
Share on other sites

Posted

of course my is slow. but has more option.

Share this post


Link to post
Share on other sites

Posted

nice work. Finally something which seems to be able to find more pictures then just one, do I understand it right? You just could try to write comments in english man :)

Share this post


Link to post
Share on other sites

Posted

hello pal, i am try to make a loop of your way, but no luck, could you please take a look and tell me whats happening...

#include <array.au3>
#include <myImageSearch.au3>
func exittheprog ()
   Exit
EndFunc
HotKeySet( "{F10}", "exittheprog" )
while 1

   sleep(1000)
    MouseMove(969,844)
MouseClick("left")

;########## Number0 ##########
Global $Number0
Global $time1
Global $ImageSearch = @ScriptDir & "images0.bmp"
Global $x = 0
Global $y = 0
Global $w = @DesktopWidth
Global $h = @DesktopHeight
Global $ColorTrans = ''
Global $mOnlyFirst = True
Sleep(10)
$time1 = TimerInit()
$Number0 = myImageSearch_Desktop($ImageSearch, $x, $y, $w, $h, $ColorTrans, $mOnlyFirst)
If @error Then ConsoleWrite("sorry image not exist" & @CRLF)
ConsoleWrite("time 1: " & TimerDiff($time1) / 1000 & ' sek.' & @CRLF)
If IsArray($Number0) Then
    MouseMove(1443,457)
MouseClick("left")
send ("0")
Send ("{ENTER}")
  
Else
    MouseMove(969,844)
MouseClick("left")
EndIf
sleep(1000)
  MouseMove(969,844)
MouseClick("left")
;##################################
WEnd

Share this post


Link to post
Share on other sites

Posted (edited)

hello pal, i am try to make a loop of your way, but no luck, could you please take a look and tell me whats happening...

maybe u have wrong format.

create picture:

#include <ScreenCapture.au3>
_ScreenCapture_Capture(@ScriptDir & "testscren.bmp", 100, 100, 120 , 120)

find:

#include <myImageSearch.au3>
HotKeySet("{F10}", "exittheprog")
Global $Number0
Global $Error
Global $ImageSearch = @ScriptDir & "testscren.bmp"
While 1
$Number0 = myImageSearch_Desktop($ImageSearch)
$Error = @error
If $Error Then ConsoleWrite("sorry image not exist. Error nr:" & $Error & @CRLF)
If IsArray($Number0) Then
  ConsoleWrite("Pos: " & $Number0[0] & " : " & $Number0[1] & @CRLF)
  MouseMove($Number0[0], $Number0[1])
EndIf
Sleep(1000)
WEnd
Func exittheprog()
Exit
EndFunc   ;==>exittheprog
Edited by akurakkauaaa

Share this post


Link to post
Share on other sites

Posted

How about game screen (scaled)?

Share this post


Link to post
Share on other sites

Posted

Hi,

What about can this work with IE? like for example capture an flash object, which could be a upload buttons. If it does not work with IE, any thought about integrate with it IE?

This will be greatly useful.

Share this post


Link to post
Share on other sites

Posted

Works great THX!

nice that you also posted a good example

Share this post


Link to post
Share on other sites

Posted

anything to do with 32/64 bit?

Share this post


Link to post
Share on other sites

Posted

of course my is slow. but has more option.

 

Probably it's slow... but it works quite well, but I found a strange behavior: when I look for an image (actually, an icon) at the desktop, using '_ImageSearch_Desktop' function, it doesn't find it, but when I look for the same icon in a specific area of the desktop, using following code (yeah, it's derived from yours!):

; #FUNCTION# ====================================================================================================================
; Name...........: _ImageSearch_Position
; Description ...: Image search in a position of the desktop, according to provided width and height
; Syntax.........: _ImageSearch_Position($Image, $Position, $Width, $Height, $TransColorRGB = '')
; Parameters ....: $Image - search image: string address for file, or bitmap (format .bmp 24-bit)
;                  $Position - topleft, topcenter, topright, middleleft, center (default), middleright, bottomleft, bottomcenter, bottomright
;                  $Width - width of searching area [Default is @DesktopWidth.]
;                  $Height - height of searching area [Default is @DesktopHeight.]
;                  $TransColorRGB - Color transparency / Ignore color. Must be string and format RGB. a.g: "0xFFFFFF".[Default is "".]
;
; Return values . : On Success - Returns two-element array coordinates, or 2D array coordinates. CENTER of search image.
;                   On Failure - @Error = 1 - Path not found or invalid image/bitmap.
;                                @Error = 2 - Image not exist (in searching area).
; ===============================================================================================================================

Func _ImageSearch_Position($Image, $Position = "center", $width = @DesktopWidth, $height = @DesktopHeight, $TransColorRGB = '')
    Local $aCoords[4], $aReturn, $error

    ;Some initial checks
    $width = Int($width)
    $height = Int($height)
    If $width = 0 Or $width > @DesktopWidth Then
        $width = @DesktopWidth
    EndIf
    If $height = 0 Or $height > @DesktopHeight Then
        $height = @DesktopHeight
    EndIf

    ;Coordinates calculation
    Switch $Position
        Case "topleft"
            $aCoords[0] = 0
            $aCoords[1] = 0
        Case "topcenter"
            $aCoords[0] = Int((@DesktopWidth - $width) / 2)
            $aCoords[1] = 0
        Case "topright"
            $aCoords[0] = @DesktopWidth - $width
            $aCoords[1] = 0
        Case "middleleft"
            $aCoords[0] = 0
            $aCoords[1] = Int((@DesktopHeight - $height) / 2)
        Case "middleright"
            $aCoords[0] = @DesktopWidth - $width
            $aCoords[1] = Int((@DesktopHeight - $height) / 2)
        Case "bottomleft"
            $aCoords[0] = 0
            $aCoords[1] = @DesktopHeight - $height
        Case "bottomcenter"
            $aCoords[0] = Int((@DesktopWidth - $width) / 2)
            $aCoords[1] = @DesktopHeight - $height
        Case "bottomright"
            $aCoords[0] = @DesktopWidth - $width
            $aCoords[1] = @DesktopHeight - $height
        Case Else ;"center"
            $aCoords[0] = Int((@DesktopWidth - $width) / 2)
            $aCoords[1] = Int((@DesktopHeight - $height) / 2)
    EndSwitch
    $aCoords[2] = $aCoords[0] + $width
    $aCoords[3] = $aCoords[1] + $height

    $aReturn = _ImageSearch_Desktop($Image, $aCoords[0], $aCoords[1], $aCoords[2], $aCoords[3], $TransColorRGB)
    $error = @error

    Switch $error
        Case 0
            Return $aReturn
        Case 1
            Return SetError(1, 1, '')
        Case 2
            Return SetError(2, 2, '')
    EndSwitch
EndFunc   ;==>_ImageSearch_Position

It finds it!

I think the reason is that my desktop is quite big (1920x1200), and the original code 'get lost'. As I know that the icon is located in a specific area of the desktop, I can search in a smaller area.

Anyway, thanks a lot for your code!

Share this post


Link to post
Share on other sites

Posted (edited)

This is a great UDF. Thank you!

Be sure you save as 24bit BMP or it wont find the image.

Edited by BrandonHaley

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0