Jump to content
Centrally

ImageSearch Usage Explanation

Recommended Posts

When I have this part of the code:

local $search = _ImageSearchArea('check5.bmp', 1, 800, 40, 900, 80, $x, $y, 0)

Does the first parameter dictate the tolerance? In the code above that would be "1" or how do I dictate the tolerance as I have an image which is semi transparent which I would like to find no matter what screen is in the background.

Share this post


Link to post
Share on other sites

I was trying to write a script that could check several areas searching for a specific BMP at the same time but I don't know how to use more than one imagesearcharea. Sorry for this, I'm a noob. Any help would be appreciated. Thanks

Share this post


Link to post
Share on other sites

Hmm not sure you can, it follows a pattern of search. Experts chime in pls.


Spoiler

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Share this post


Link to post
Share on other sites

I have written a simple code and it's working great. Thanks for the great library. Here are a snippet -

WinActivate('My Window')

$x = 0
$y = 0
If _ImageSearch('searchButton.PNG', 1, $x, $y, 20) = 1 Then
   Return 1
ElseIf _ImageSearch('bundle.PNG', 1, $x, $y, 20) = 1 Then
   Send('{ESC}{LCTRL}{LCTRL}{LCTRL}')
   sleep(1000)
Else
   Send('{LCTRL}')
EndIf

Now my question is how can I use that _ImageSerach function in a specific program (background process) so that I can use my pc to do other work?

I know how to use control commands to click on background but I can't use _ImageSerach in background.

Please help.

Share this post


Link to post
Share on other sites

Because, i believe, it doesn't work in the background, you have to be able to see the image yourself, in order for the code to work.


Spoiler

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Share this post


Link to post
Share on other sites
6 hours ago, smahmud said:

Now my question is how can I use that _ImageSerach function in a specific program (background process) so that I can use my pc to do other work?

I know how to use control commands to click on background but I can't use _ImageSerach in background.

It takes a screenshot and finds the image you requested!
So it does not work with hidden windows or background processes!


Regards,
 

Share this post


Link to post
Share on other sites

Thanks for the reply :)

I guess only way to do is screen capture on specific window and run search on that picture but I am not sure if there any function exists to do that.

One more question: How can i look for multiple occurrence of same image and return all the cords?

Thanks.

Share this post


Link to post
Share on other sites
On 7/2/2017 at 3:13 PM, MazeM said:

Then there's still a bug in the code, you cannot use black as its color value is zero, and only non-zero is accepted as transparent:

If $transparency <> 0 Then $findImage = "*" & $transparency & " " & $findImage

 

I had to change the ImageFile parameter when calling the DLL function to get transparency to work. It was missing the correct prefix for the transparency option.

For reference, the Image file options are here: https://autohotkey.com/docs/commands/ImageSearch.htm

*TransN: This option makes it easier to find a match by specifying one color within the image that will match any color on the screen. 

This is my updated _ImageSearchArea function with the transparency option fixed. Notice the inclusion of the *Trans text in the ImageFile parameter parameters.

If $transparency <> 0 Then $ImageFileOptions = "*Trans" & Hex($transparency) & " " & $ImageFileOptions

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()

   Local $ImageFileOptions = ""
   If $tolerance > 0 Then $findImage = "*" & $tolerance & " " & $ImageFileOptions
   If $transparency <> 0 Then $ImageFileOptions = "*Trans" & Hex($transparency) & " " & $ImageFileOptions
   $ImageFileOptions = $ImageFileOptions & $findImage

   $result = DllCall($h_ImageSearchDLL, "str", "ImageSearch", "int", $x1, "int", $y1, "int", $right, "int", $bottom, "str", $ImageFileOptions)
   If @error Then Return "DllCall Error=" & @error
   If $result = "0" Or Not IsArray($result) Or $result[0] = "0" Then Return False

    $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 True
    EndIf
EndFunc   ;==>_ImageSearchArea

 

Share this post


Link to post
Share on other sites

Hi guys!

 

So I´ve been playing around with AutoIt again after a couple of years of absence. I'm trying to make ImageSearch work in my favor and got a test script going that looks like this: 

#include <ImageSearch2015.au3>



Local $findImage[8], $resultPosition, $tolerance, $transparency, $waitSecs, $x, $y

$findImage[0] = 7
$findImage[1] = "C:\Users\Micke\Desktop\AutoIt Script\ImageSearch2015\HK.png"
$findImage[2] = "C:\Users\Micke\Desktop\AutoIt Script\ImageSearch2015\K4.png"
$findImage[3] = "C:\Users\Micke\Desktop\AutoIt Script\ImageSearch2015\K5.png"
$findImage[4] = "C:\Users\Micke\Desktop\AutoIt Script\ImageSearch2015\R8.png"
$findImage[5] = "C:\Users\Micke\Desktop\AutoIt Script\ImageSearch2015\S7.png"
$findImage[6] = "C:\Users\Micke\Desktop\AutoIt Script\ImageSearch2015\S8.png"
$findImage[7] = "C:\Users\Micke\Desktop\AutoIt Script\ImageSearch2015\SJ.png"

$x=0
$y=0
$waitSecs = 1

  $findImage =  _WaitForImagesSearch($findImage, $waitSecs, $resultPosition, $x, $y, $tolerance, $transparency = 0)
ConsoleWrite($findImage & @CRLF)

It works but kind of slow(2.5 s) and the area I want to search for those .png's is much smaller than my desktop, so my question is how would I go about setting that smaller area up in my script?

Share this post


Link to post
Share on other sites

Yes

Spoiler

Sorry, not enough info? Perhaps if you gave more detail about what you're trying to do you'd get more in return ;)

 

Edited by JLogan3o13

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Share this post


Link to post
Share on other sites
1 hour ago, JLogan3o13 said:

Yes

  Hide contents

Sorry, not enough info? Perhaps if you gave more detail about what you're trying to do you'd get more in return ;)

 

Wow great and easy. If someone  will search it

 

#AutoIt3Wrapper_Res_File_Add=img\search.bmp, rt_bitmap, TEST_BMP_1
Global $x, $y
Global $pic1
; set BMP image to picture control from resource  bitmap
_ResourceSetImageToCtrl($pic1, "TEST_BMP_1", $RT_BITMAP)

Case $imageSearch
            Local $find = _ImageSearch($pic1,0,$x,$y,0)
            If $find Then
                MouseMove($x,$y,10)
            Else
                MsgBox(0,"","Not Found")
            EndIf

 

Share this post


Link to post
Share on other sites

Guys i have a problem i have at the same folder the ImageSearch.au3 file and the dll and also my new script and when i make the imagesearch at my main script its not working i have made the include at the start of my sciprt whats wrong?

Share this post


Link to post
Share on other sites
28 minutes ago, TolisX said:

whats wrong?

you didn't post the script so we either do a wild guess or you share enough information to a a proper look. :)

Jos


SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

That's not a script, it's a picture of a script. Kind of like taking a picture of an apple doesn't feed you, giving us code in a picture doesn't help us help you.

The only thing I can guess is that you're trying to use the 64 bit image search, and running it as an x86 process. Due to the naming you're giving things and the fact that the x86 version of AutoIt is being executed.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

UDF has

#include-once at the top

If i include entire UDF (well, the main function of it) in my main script, what difference does it make ?.

I would end up with this.

 

#include "GDIPlus.au3";Required to get ImageSearch to function. Comes with AutoIT
Global $iX, $iY;Make these variables global so we can reuse them after finding an image, instead of creating new variables for that purpose.
Global $xCenter, $yCenter ;these are the final result of the CENTER Of the found image
Do
    Sleep(300)
Until _FindImage("Example.jpg")
MsgBox(0, "Example", $xCenter & @CRLF & $yCenter)
MouseMove ($xCenter ,$yCenter) ;Mov mouse to the center of found image
Func _FindImage($sImgPath);the function that searches

    ;Initialize and prepare ImageSearch.
    _GDIPlus_Startup();Initialize Microsoft Windows GDI+.
    Local $hImage = _GDIPlus_ImageLoadFromFile($sImgPath);Create an image object based on a file.
    Local $hHBmp = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage);Create a handle to a bitmap from a bitmap object.

    ;Search for Image.
    $iRet = _ImageSearch($hHBmp, 1, $iX, $iY, 10) ; Default=5: Tolerance, if it does not work for you rise it (up to 255)

    ;Begin Cleanup.
    _WinAPI_DeleteObject($hHBmp);Deletes a logical pen, brush, font, bitmap, region, or palette.
    _GDIPlus_ImageDispose($hImage);Release an image object.
    _GDIPlus_Shutdown();Clean up resources used by Microsoft Windows GDI+.

    ;Report Result.
    Return $iRet;Will return 1 if image was found. If no image was found, this will return 0.

EndFunc   ;==>_FindImage

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

Func _ImageSearchArea($findImage,$resultPosition,$x1,$y1,$right,$bottom,$x,$y, $tolerance,$HBMP=0)

    If IsString($findImage) Then
        if $tolerance>0 then $findImage = "*" & $tolerance & " " & $findImage
        If $HBMP = 0 Then
            $result = DllCall("ImageSearchDLL.dll","str","ImageSearch","int",$x1,"int",$y1,"int",$right,"int",$bottom,"str",$findImage)
        Else
            $result = DllCall("ImageSearchDLL.dll","str","ImageSearchEx","int",$x1,"int",$y1,"int",$right,"int",$bottom,"str",$findImage,"ptr",$HBMP)
        EndIf
    Else
        $result = DllCall("ImageSearchDLL.dll","str","ImageSearchExt","int",$x1,"int",$y1,"int",$right,"int",$bottom, "int",$tolerance, "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
    $array = StringSplit($result[0],"|")
   $x=Int(Number($array[2])) ;this is x most left
   $y=Int(Number($array[3])) ;This is y most high
   if $resultPosition=1 then
      $xCenter=$x + Int(Number($array[4])/2) ;x center
      $yCenter=$y + Int(Number($array[5])/2) ;y center
   endif
   return 1
EndFunc

 

Is there something i need to worry about when running this code like that in a loop ?
My main script will continuously look for that image until all its instances are gone.

I am trying to click off inventory items automatically.

 

Share this post


Link to post
Share on other sites

Hello Centrally,

I tried using your code above with ImageSearch.au3 in Windows 10 x64 and it just hangs; see my code below, are you able to assist?, thank you.

#include <ImageSearch.au3>

HotKeySet("p", "checkForImage")

global $y = 0, $x = 0

Func checkForImage()
local $search = _ImageSearchArea('d:\autoit\Test.bmp', 1, 800, 40, 900, 80, $x, $y, 0)
If $search = 1 Then
MouseMove($x, $y, 20)
EndIf
EndFunc

while 1
sleep(200)
WEnd

Share this post


Link to post
Share on other sites

 The function has one more parameter, bitmap in the end, can be set to 0 try adding it like this.

_ImageSearchArea('d:\autoit\Test.bmp', 1, 800, 40, 900, 80, $x, $y, 0, 0) 

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

Searching within a rectangle with 100x40.


Spoiler

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

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

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By zuladabef
      All my scripts were working fine and now I am getting this error.  How do I resolve it?  Which folder(s) do the DLLs need to be in?
      ! Dll not found or Call Dll error !  
    • By Synaps3
      I've recently been annoyed by how google images works. You can't click an image and see the full res image. You have to go to the website and find the image on the page and occasionally, it won't allow you to view the image easily. This script makes it easy to view any image in google images in full resolution immediately. You just press Ctrl + Q while hovering over the image you want and it'll open full res in a new tab. This is only tested in firefox, but it shouldn't be hard to modify for another browser.
      Here it is:
      #include <Misc.au3> #include <MsgBoxConstants.au3> #include <AutoItConstants.au3> #include <Clipboard.au3> #include <Array.au3> #include <String.au3> Local $clipB Local $urlArray Local $theLink HotKeySet("^q", "OpenImage") Func DecodeUrl($src) Local $i Local $ch Local $buff ;Init Counter $i = 1 While ($i <= StringLen($src)) $ch = StringMid($src, $i, 1) ;Correct spaces If ($ch = "+") Then $ch = " " EndIf ;Decode any hex values If ($ch = "%") Then $ch = Chr(Dec(StringMid($src, $i + 1, 2))) $i += 2 EndIf ;Build buffer $buff &= $ch ;Inc Counter $i += 1 WEnd Return $buff EndFunc ;==>DecodeUrl Func OpenImage() MouseClick($MOUSE_CLICK_RIGHT) Send("A") Sleep(100) $clipB = _ClipBoard_GetData($CF_TEXT) $theLink = DecodeUrl($clipB) $urlArray = _StringBetween($theLink, "=", "&") If StringInStr($urlArray[0], "?") <> 0 Then $urlArray = _StringBetween($theLink, "=", "?") EndIf ShellExecute($urlArray[0]) EndFunc While 1 Wend  
    • By Schuster
      Hey there,
      i need your help guys. I am working in the QA department of my company. A little part of or software produces hints (like little popups) which needs to be tested every release. I wrote scripts to trigger those hints and i also implemented the imagesearch.dll to find those hints on the screen. My goal now is it to let the machine work over night, so when i come back to work i only get a report which says 130/140 hints were found successfully. This already works, aslong as my pc is not locked, but i want/need to lock my pc because of security concerns.
      My general question. Is it possible to run my scripts on my locked PC and still find an image that i provide which will open sooner or later in the background?
       
      Thanks in advance
    • By kylejustknows
      The code is solid and simple, it can almost explain itself.
      This is the native autoit way to do the "imagesearch", no 3rd party .dll needed.
       
      It gets "your.bmp", and "screenshot.bmp" ----> Convert the  .bmp files into 2D-Arrays (Malkey's function)  ----> Compare the 2D-arrays, return the matched position.
       
      Tested on: Windows 7; Windows server 2008R2; Windows 10 1809.
       
      Pros:
      It is native. No extra .dll needed
      It is super robust. (I used to have lots of funny results using other imagesearch libs).
      It gets screenshot the same you get your screenshot crop, so it always gets a solid result, and 100% accurate.
      The code is very simple and friendly, all level users can understand and use it.
       
      Cons:
      It is slow to convert your.big.screen.bmp into a 2D-array, and may consume 200+MB of memory and may take 5 - 20 seconds to return the result. (the actual search in an array is fast, but the conversion from .bmp to array is slow. The speed depends on your CPU speed and your screen size).
      Correct: now optimized,  it's ~5 seconds and ~ 70MB ram usage.
      It is a pixel-by-pixel color-code strict comparison in the "array-in-array" search, so you have to use the 24-bit BMP file, no "Tolerance" allowed.
       
      2019-Jun-11: script update:
      Same day updated: Update example;  Optimize the algorithm for performance, now most computers can get the result in ~5 seconds, using ~70MB temporary memory, for the 1920x1080 resolution screen.
       
      2019-Jun-12 script update:
      It now uses "PrintScreen" hotkey to save the screenshot.bmp (restores the user's old clipboard content after it is done) ~This is the only way to make sure the screenshot matches exactly what the user is seeing, after doing dozens of harsh tests.
      The reason: The UDF "ScreenCapture" and "ImageSearch.dll"  are not reliable for an unknown reason. Some window/dialogue special drawings are "invisible" in their screenshots.
      But the "PrintScreen" key -> Clipboard -> screenshot.bmp, this method always catches exact things showing on the screen.
       
      #include <GDIPlus.au3> #include <ClipBoard.au3> ;Sinple Example.================== the 1.bmp is what you want to find on your screen $result = _ScreenSearchBmp("1.bmp") if $result[0] = 0 Then MsgBox(0,"","not found") Else MouseMove($result[0],$result[1],20) ;move mouse to the result EndIf ;Example End.================== You can "include" this file after you remove this "Example" part here. ;=============================================================================== ; ; Description: Main Function. Find the position of an image on the desktop ; Parameter(s): ; $center = 1 - Set where the returned x,y location of the image is. ; default 1 means center, 0 means top-left ; ; Return Value(s): On Success - Returns the array of matched position [x,y] on your screen. ; On Failure - Returns array [0,0] (BTW, there is no position 0,0 on a screen, so it means error) ; ; Note: Warning: The BMP file must be a 24-bit BMP (windows default) ; ;=============================================================================== Func _ScreenSearchBmp($file,$center=1) local $pixelarray,$screenarray ;get both your image.bmp and screenshot.bmp into pixel-by-pixel 2D arrays _FileImageToArray($file, $pixelarray) _Clip_screenshot(@TempDir & "\screenshot.bmp") _FileImageToArray(@TempDir & "\screenshot.bmp",$screenarray) FileDelete(@TempDir & "\screenshot.bmp") ;compare the 2 2D-arrays local $result = _2darray_in_2darray($screenarray,$pixelarray) ;result tidy up, for if $center=1, and for if not found. Local $aresult[2] $aresult[0] = $result[0] $aresult[1] = $result[1] if $aresult[0] = 0 then Return $aresult ;if not found , return 0 0 here if $center = 1 then $aresult[0] = $result[0]+ Round(UBound($pixelarray,1)/2) if $center = 1 then $aresult[1] = $result[1]+ Round(UBound($pixelarray,2)/2) Return $aresult ;if ALL GOOD, and $center=1 then return the center of the image here. EndFunc ;=============================================================================== ; Code by Malkey, converts .bmp into 2D array pixal by pixal. : thanks man! ;=============================================================================== Func _FileImageToArray($filename, ByRef $aArray) Local $Reslt, $stride, $format, $Scan0, $iW, $iH, $hImage Local $v_Buffer, $width, $height Local $i, $j _GDIPlus_Startup() $hImage = _GDIPlus_ImageLoadFromFile($filename) $iW = _GDIPlus_ImageGetWidth($hImage) $iH = _GDIPlus_ImageGetHeight($hImage) $Reslt = _GDIPlus_BitmapLockBits($hImage, 0, 0, $iW, $iH, $GDIP_ILMREAD, $GDIP_PXF32ARGB) ;Get the returned values of _GDIPlus_BitmapLockBits () $width = DllStructGetData($Reslt, "width") $height = DllStructGetData($Reslt, "height") $stride = DllStructGetData($Reslt, "stride") $format = DllStructGetData($Reslt, "format") $Scan0 = DllStructGetData($Reslt, "Scan0") Dim $aArray[$width][$height] For $i = 0 To $iW - 1 For $j = 0 To $iH - 1 $aArray[$i][$j] = DllStructGetData(DllStructCreate("dword", $Scan0 + ($j * $stride) + ($i * 4)), 1) Next Next _GDIPlus_BitmapUnlockBits($hImage, $Reslt) _GDIPlus_ImageDispose($hImage) _GDIPlus_Shutdown() Return EndFunc ;==>_FileImageToArray ;=============================================================================== ; ; Description: ; My code, search a 2D array inside another 2d array ; If found, return the positon of first element ; If error or not found, return array [0,0]. Because the very first match would be [1,1], "0" means something wrong. ; eg. search a 2d array ; [1,2,3,4] ; [5,6,7,8] ; [9,0,1,2] ; for: ; [7,8] ; [1,2] ; You will get result [2,3] (means, matched, first element position is row 2, colunm 3) ; ; Parameter(s): ; ; Return Value(s): On Success - Returns the array of matched [x,y], the top-left element position in the source. ; On Failure - Returns [0,0] ; ; ;=============================================================================== Func _2darray_in_2darray($source,$search) ;get the size of the both arrays local $sourcerow = UBound($source,1) Local $sourcecol = UBound($source,2) local $searchrow = UBound($search,1) Local $searchcol = UBound($search,2) ;error input cheching, if error return position 0,0 if $sourcerow = 0 or $sourcecol = 0 or $searchrow = 0 or $searchcol = 0 then Local $aPeople[2] $aPeople[0] = 0 $aPeople[1] = 0 Return $aPeople EndIf ; A crazy 4-for-loops, compare every x,y of search array in every x,y in source array for $ssr = 1 to $sourcerow - $searchrow +1 for $ssc = 1 to $sourcecol - $searchcol +1 for $sr = 1 to $searchrow for $sc = 1 to $searchcol ;if an element not match, go back, search for next if $search[$sr-1][$sc-1] <> $source[$ssr+$sr-2][$ssc+$sc-2] then ContinueLoop 3 Next Next ;if the loop passed all elements test, made it here, means the result is found! congress! lets return the result: Local $aPeople[2] $aPeople[0] = $ssr $aPeople[1] = $ssc Return $aPeople Next Next ;all the loops finished, no result found. return [0,0] Local $aPeople[2] $aPeople[0] = 0 $aPeople[1] = 0 Return $aPeople EndFunc ; #FUNCTION# ==================================================================================================================== ; Name ..........: _Clip_screenshot ; Description ...: This get a screenshot.bmp using "Print Screen" key, so the image is EXACT same image you use "Print Screen" key, to avoid funny results. ; Syntax ........: _Clip_screenshot($file) ; Parameters ....: $file - The location of the screen shot .bmp file you want it to save ; Return values .: None ; Author ........: Kyle ; =============================================================================================================================== Func _Clip_screenshot($file) local $tempdata = _ClipBoard_GetData() ;save current user's clipboard Send("{PRINTSCREEN}") sleep(200) If _ClipBoard_IsFormatAvailable($CF_BITMAP) Then _ClipBoard_Open(0) $hClipboardImage = _ClipBoard_GetDataEx($CF_BITMAP) _ClipBoard_Close() _GDIPlus_Startup() $hBitmap = _GDIPlus_BitmapCreateFromHBITMAP($hClipboardImage) Local $iX = _GDIPlus_ImageGetWidth($hBitmap) Local $iY = _GDIPlus_ImageGetHeight($hBitmap) Local $hClone = _GDIPlus_BitmapCloneArea($hBitmap, 0, 0, $iX, $iY, $GDIP_PXF24RGB) ;make sure its 24bit bmp _GDIPlus_ImageDispose($hBitmap) $hBitmap = $hClone $sCLSID = _GDIPlus_EncodersGetCLSID("BMP") _GDIPlus_ImageSaveToFileEx($hBitmap, $file, $sCLSID, 0) _GDIPlus_BitmapDispose($hBitmap) _GDIPlus_Shutdown() EndIf _ClipBoard_SetData($tempdata) ; restore user clipboard EndFunc Remove the "example" part then you can include this code as a file.
    • By kuhicop
      Hello, I need to find an image on screen and return it's position left, top, right, botton.
      I'm using the ImageSearch function but it only returns 1 or 0.
      Any ideas? Thanks!
×
×
  • Create New...