Search code examples
autoit

autoit imagesearch transparency parameter not working


i need to use search transparent image on screen. i tried some librarys. but those are not working as my want.

help me. how i can done this enter code here

#include "ImageSearch2015.au3"
#include <Date.au3>

Global $x = 0
Global $y = 0

HotKeySet("{UP}","hey")
HotKeySet("{DOWN}","heyo")

Func hey()
    $balikcisaniye = _Date_Time_GetTickCount()
    $array = _ImageSearchArea("bul.bmp", 1, 0, 0, @DesktopWidth/2, @DesktopHeight/2, $x, $y, 2,0x000000)
    if($array = True) Then 
        $balikcisaniye1 = _Date_Time_GetTickCount()
        MouseMove($x,$y)
        MsgBox(1,"","Found." & $x & "-" & $y & " / " & $balikcisaniye1-$balikcisaniye)
    Else
        MsgBox(1,"","Not Found.")
    EndIf
EndFunc

Func heyo()
    exit
EndFunc

while 1
WEnd

the library used on this script : (KutayAltinoklu)

https://www.autoitscript.com/forum/topic/148005-imagesearch-usage-explanation/page/4/


Solution

  • Bug!

    Ok, I tested it and found a bug in UDF. It cannot work as it is.

    • Open ImageSearch2015.au3 (or whatever you renamed it to)
    • find the line starting with if $transparency <> 0 (line# 137 of unmodified ImageSearch2015.au3)
    • replace that condition with if IsString($transparency) it should now work as described below

    Usage

    It appears that the UDF uses ImageSearch DLL from AutoHotkey. This is its documentation.

    If that is true then the linked UDF's documentation is wrong/incomplete.

    Here is what AHK's documentation says:

    This option makes it easier to find a match by specifying one color within the image that will match any color on the screen. It is most commonly used to find PNG, GIF, and TIF files that have some transparent areas (however, icons do not need this option because their transparency is automatically supported). For GIF files, TransWhite might be most likely to work. For PNG and TIF files, TransBlack might be best. Otherwise, specify some other color name or RGB value

    BMP does not support built-in transparent color but that should be fine - you just need to designate any one color as transparent - that color will be ignored

    I've read the docs and UDF source and it seems that this is what should be passed as transparency parameter:

    either:

    • string "TransBlack" if transparent color is black (000000) or
    • string "TransWhite" if transparent color is white (FFFFFF) or
    • string "Trans224466" otherwise - where 224466 is string HEX of color designated as transparent
      • That is, if your color is stored as integer, you will need to do something like "Trans" & hex(0x998877, 6) where 0x998877 is the color

    Example

    For example if your image bul.bmp has a picture drawn upon background color #808080 (50% grey). So if you call the function like this:

    $array = _ImageSearchArea("bul.bmp", 1, 0, 0, @DesktopWidth/2, @DesktopHeight/2, $x, $y, 2, "Trans808080")
    

    ...all background (50% grey) pixels of bul.bmp should match any colors on screen, that is - those pixels will be ignored.

    That is, if bul.bmp is just a solid 50% grey rectangle with no other color, the function will always match. If it has one non-gray pixel at any position, it will match if screen contains a pixel of that color, etc.