Jump to content
Centrally

ImageSearch Usage Explanation

Recommended Posts

I dont speak english. Forgive me for any error in text.

I put the dll to work in 32 and 64 bits, but the dll returns wrong coordinates on Windows 10.  In some areas the image is not even found.

Ex: The image is in coord: 586,168 and the dll returns 443,56. On changes image position the precision varies.
Someone know a fix?

Thanks for your attention, greetings.

Share this post


Link to post
Share on other sites

Post your code, there may be something wrong about the way you're using it.


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
15 hours ago, careca said:

Post your code, there may be something wrong about the way you're using it.

Thank you for you attention.

I find a solution for the problem in this topic.

Below the working script code with modifications for solve the problem. The @OSVersion don't returns WIN_10 in Windows 10, returns 9600. But at last the script is finding the image on screen with right coordinates. :)

#include <ImageSearch2015.au3>
AutoItSetOption("MouseCoordMode", 1)
#AutoIt3Wrapper_Res_HiDpi=Y
HotKeySet("p", "checkForImage")
HotKeySet("o", "showCoords")

If @OSVersion="WIN_10" Then
    DllCall("Shcore.dll","long","PROCESS_DPI_AWARENESS",1)
Else
    DllCall("User32.dll","bool","SetProcessDPIAware")
EndIf

Global $x = 0, $y = 0
ConsoleWrite(@OSBuild & @CR)
ConsoleWrite(@DesktopWidth & @CR & @DesktopHeight & @CR)

Func checkForImage()
    Local $search = _ImageSearch("tst.bmp", 1, $x, $y, 0)
    If $search = 1 Then
        ConsoleWrite($x & @CR & $y & @CR)
        MouseMove($x, $y, 0)
    EndIf
EndFunc   ;==>checkForImage

Func showCoords()
    $mousepos = MouseGetPos()
    ToolTip($mousepos[0] & "," & $mousepos[1])
    ConsoleWrite($mousepos[0] & @CR & $mousepos[1] & @CR)
EndFunc   ;==>showCoords

While 1
    Sleep(200)
WEnd

 

Share this post


Link to post
Share on other sites

Glad it's solved. :)


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

Win10 x64 Anniversary

Was working with this today, got the old original files working (Once I found the .dll files need to be in the same directory as my script, not the Include folder)

Tried the newer ImageSearch2015 version to see whats new/better and for some reason that one does not work for me at all.  No errors, spins a few times the cursor to let me know its thinking and just doesn't do anything.

 

Tried to move around the .dll files and like I had to do for the old version, no difference in effect. 

 

Anybody know exactly what is supposed to be different/better with the 2015 version (I guess it auto senses OS architecture so you do not have to manually install the proper .dll?) and what the issue may be for this system (I guess the Win10 anniversary is so new that the code was not written to work with it)

 

T

Share this post


Link to post
Share on other sites
On 12/13/2016 at 9:07 AM, gillall said:

Thank you for you attention.

I find a solution for the problem in this topic.

Below the working script code with modifications for solve the problem. The @OSVersion don't returns WIN_10 in Windows 10, returns 9600. But at last the script is finding the image on screen with right coordinates. :)

#include <ImageSearch2015.au3>
AutoItSetOption("MouseCoordMode", 1)
#AutoIt3Wrapper_Res_HiDpi=Y
HotKeySet("p", "checkForImage")
HotKeySet("o", "showCoords")

If @OSVersion="WIN_10" Then
    DllCall("Shcore.dll","long","PROCESS_DPI_AWARENESS",1)
Else
    DllCall("User32.dll","bool","SetProcessDPIAware")
EndIf

Global $x = 0, $y = 0
ConsoleWrite(@OSBuild & @CR)
ConsoleWrite(@DesktopWidth & @CR & @DesktopHeight & @CR)

Func checkForImage()
    Local $search = _ImageSearch("tst.bmp", 1, $x, $y, 0)
    If $search = 1 Then
        ConsoleWrite($x & @CR & $y & @CR)
        MouseMove($x, $y, 0)
    EndIf
EndFunc   ;==>checkForImage

Func showCoords()
    $mousepos = MouseGetPos()
    ToolTip($mousepos[0] & "," & $mousepos[1])
    ConsoleWrite($mousepos[0] & @CR & $mousepos[1] & @CR)
EndFunc   ;==>showCoords

While 1
    Sleep(200)
WEnd

 

Hey I have the same problem on my new windows 10 surfacebook its a super high res display. I cant see to get my imagesearch to work, & I tried your code do you have any ideas on how to fix this?

Share this post


Link to post
Share on other sites

So, exact same code, and the image with the correct name in script dir?

Did you try to debug? What does

@OSVersion

retrieve on your end? What is your autoit version?

How does this work for you?

#include <ImageSearch.au3>
Local $HBMP = 0
Local $x1 = 0, $y1 = 0
Local $right = @DesktopWidth
Local $bottom = @DesktopHeight
Local $findImage = @ScriptDir&'\Capture.PNG'
While 1
    $result = DllCall("ImageSearchDLL.dll","str","ImageSearch","int",$x1,"int",$y1,"int",$right,"int",$bottom,"str",$findImage,"ptr",$HBMP)
    If $result[0]<>0 Then
        $array = StringSplit($result[0],"|")
        ConsoleWrite('XPos - '& $array[2] &' - YPos - '& $array[3] &' - XSize - '&$array[4]&' - YSize - '&$array[5]&@CRLF)
    EndIf
    Sleep(100)
WEnd

 

Edited by careca

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

Hi my script dont work 

#include <ImageSearch.au3>
#include <GDIPlus.au3>
$fileA = "C:\Users\benne\OneDrive\skrivbord\ImageSearch 32bit\gg.bmp"

_GDIPlus_Startup()

$hImageA = _GDIPlus_ImageLoadFromFile($fileA) ;this is the firefox icon use something else if you don't have it.
$hBitmapA = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImageA)

$x = 0
$y = 0

$result = _ImageSearch($hBitmapA, 1, $x, $y, 20) ;Zero will search against your active screen
If $result > 0 Then
MouseMove($x, $y)
MsgBox (0, "Result", $Result)
EndIf
MsgBox (0, "Result", $Result)
_GDIPlus_ImageDispose($hImageA)
_GDIPlus_Shutdown()


>Exit code: 3221225477    Time: 1.492

whats wrong?

Share this post


Link to post
Share on other sites
9 hours ago, careca said:

So, exact same code, and the image with the correct name in script dir?

Did you try to debug? What does

@OSVersion

retrieve on your end? What is your autoit version?

How does this work for you?

#include <ImageSearch.au3>
Local $HBMP = 0
Local $x1 = 0, $y1 = 0
Local $right = @DesktopWidth
Local $bottom = @DesktopHeight
Local $findImage = @ScriptDir&'\Capture.PNG'
While 1
    $result = DllCall("ImageSearchDLL.dll","str","ImageSearch","int",$x1,"int",$y1,"int",$right,"int",$bottom,"str",$findImage,"ptr",$HBMP)
    If $result[0]<>0 Then
        $array = StringSplit($result[0],"|")
        ConsoleWrite('XPos - '& $array[2] &' - YPos - '& $array[3] &' - XSize - '&$array[4]&' - YSize - '&$array[5]&@CRLF)
    EndIf
    Sleep(100)
WEnd

im not 100% sure about this but bmp is the only format that works.

Share this post


Link to post
Share on other sites

In fact, it's a png that comes in the zip as example... did you try it?


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

So i tried imagesearch and it worked just fine.

I need it to press on the confirmation button in a game.

-snip-

Edited by Jos

Share this post


Link to post
Share on other sites

@reber03,

Welcome to the AutoIt forum. :)

Unfortunately you appear to have missed the Forum rules on your way in. (there is also a link link in my signature) 
Please read them now particularly the bit about not discussing game automation - and then you will understand why you will get no help and this thread will now be locked. :naughty:

See you soon with a legitimate question I hope. :)

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

Opps, sorry for that mistake.

It's still possible to ask if there is a way to let the script detect different kind of colors and if someone can help with it. :)

Share this post


Link to post
Share on other sites
On 8/8/2015 at 0:01 PM, guestscripter said:

I just got it to work!

I was having much trouble, reading all the threads and posts related to ImageSearch, and I'd like to help others now.

Now got it to work as a x64 and also as a x32 script using both DLLs accordingly (on a Windows 8.1 x64 PC)

One of the steps I took in debugging was putting this into (the top of) my script:

$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.
ConsoleWrite("$sOSArch=" & $sOSArch & @CR)
$sAutoItX64 = @AutoItX64 ;Check if using x64 AutoIt ;@AutoItX64 Returns 1 if the script is running under the native x64 version of AutoIt.
ConsoleWrite("$sAutoItX64=" & $sAutoItX64 & @CR)

In any case you want to be consistent about 32bit or 64bit usage, and use the right DLL etc.

What also really helped was putting in lots of debugging and error handling to zoom in on whatever specific part isn't working and why.

Credits to Centrally (very helpful usage explanation and re-uploading the files) and kangkeng for making this possible in AutoIt, as well Miguel7 from the AutoHotKey forum who also posted some helpful advice.

I've attached a zipped folder containing all of the needed Dlls and my customised Library, which also contains an example and some debugging: ImageSearch2015.zip

55c5a345e8d04.png

Take a look inside ImageSearch2015.au3 here if you like:

Hidden Content

Edit: also uploaded "ImageSearch15.au3", a version of "my" ImageSearch Library without the built-in Example and Debugging
(will require the Dlls in the .zip file though): ImageSearch15.au3

Hidden Content

I hope this helps somebody! Let me know any feedback/issues.

Hi,

Thanks for sharing the above info.

I m trying this same image search bt the script is properly working on large images, but for small images (e.g. searching a word (as an image) on screen) its not working.

Please suggest. Waiting for ur reply.

Share this post


Link to post
Share on other sites

It should work anyway. The example i posted was tested with a small image and worked, maybe the word you are searching has a bit of zoom or something?


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

Hello everybody, i'm going to use this library because it seems to do what i'm looking for. Thanks for the upload, older thread haven't got downloadable archives.

I have only few questions:

  1. Is there a built in implementation of PixelCoordMode  to avoid to write an interface for relative coordinates?
  2. Is there a way to implement non-rectangular images? [Or is there a way to implement different $tolerance for each pixel, for example using alpha channel?]
  3. Do you have some software to suggest to build images and read coordinates?

Thanks

 

Share this post


Link to post
Share on other sites

Is the transparency working for anyone?

I'm using the Imagesearch2015 of  guestscripter .

 

;                   $transparency - TRANSBLACK, TRANSWHITE or hex value (e.g. 0xffffff) of
;                                  the color to be used as transparency; can be omitted if
;                                  not needed

The imagesearch without transparency works perfect. But using the transparency like instructed above is just strange. Example:

_ImageSearch("icon.bmp", 0, $x, $y, 0, 0xffffff) ; This will always return True with $x = 0, $y = 0
; icon.bmp is a green + sign with white background.
; It also doesn't matter if there is white in the image or not or if the copy of the image is displayed. It will always return True,0,0
; If I perform the search on a limited area with _ImageSearchArea it will return True and x, y the top, left corner coordinates.

; when icon.bmp is a green + sign with BLACK background,
; using 0x000000 will always return False (unless you could find the image without transparency because its the exact same)

; Using TRANSBLACK / TRANSWHITE will also always return false

So either I don't understand something or something doesn't work.

Since this is ported from AutoHotkey, I decided to try it out the original and that works with the same images.

If someone with more knowledge could tell how to troubleshoot this. That would be great.

Share this post


Link to post
Share on other sites
On 5/6/2017 at 8:55 AM, bootybay said:

Is the transparency working for anyone?

I'm using the Imagesearch2015 of  guestscripter .

 

;                   $transparency - TRANSBLACK, TRANSWHITE or hex value (e.g. 0xffffff) of
;                                  the color to be used as transparency; can be omitted if
;                                  not needed

The imagesearch without transparency works perfect. But using the transparency like instructed above is just strange. Example:

_ImageSearch("icon.bmp", 0, $x, $y, 0, 0xffffff) ; This will always return True with $x = 0, $y = 0
; icon.bmp is a green + sign with white background.
; It also doesn't matter if there is white in the image or not or if the copy of the image is displayed. It will always return True,0,0
; If I perform the search on a limited area with _ImageSearchArea it will return True and x, y the top, left corner coordinates.

; when icon.bmp is a green + sign with BLACK background,
; using 0x000000 will always return False (unless you could find the image without transparency because its the exact same)

; Using TRANSBLACK / TRANSWHITE will also always return false

So either I don't understand something or something doesn't work.

Since this is ported from AutoHotkey, I decided to try it out the original and that works with the same images.

If someone with more knowledge could tell how to troubleshoot this. That would be great.

I'm facing the same problem right now. It's been 22 days since you bumped into the problem, have you solved it?

I hope its not, but i think its broken. ._.

Share this post


Link to post
Share on other sites

Try a 32bit color and it'll work.

;for a white background
;working 
_ImageSearch("icon.bmp", 0, $x, $y, 0, 0xffffff00) 
;or
_ImageSearch("icon.bmp", 0, $x, $y, 0, 0xffffffff) 
;or
_ImageSearch("icon.bmp", 0, $x, $y, 0, 0xffffffab)
;failing:
_ImageSearch("icon.bmp", 0, $x, $y, 0, 0xffffff)

 

 

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 think you'd have to change at least these two lines:

Func _ImageSearchArea($findImage, $resultPosition, $x1, $y1, $right, $bottom, ByRef $x, ByRef $y, $tolerance = 0, $transparency = 'not used');Credits to Sven for the Transparency addition
If IsNumber($transparency) Then $findImage = "*" & $transparency & " " & $findImage

Don't blame me if this code change doesn't work as intended, but you cannot test against any number as 0xffffffff is equal -1 and so I added a string instead. I didn't try that code nor did I check any other code lines that might break.

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...