Sign in to follow this  
Followers 0
Bundy

Searching for pixels

2 posts in this topic

#1 ·  Posted (edited)

Hi!, I'm working at function which allow me to find given pixels at selected area. I have little problem - always get correct y, but x get a bit random. I have used the easiest way (in my opinion)

HotKeySet("^s", "SSpos")
HotKeySet("^g", "Sgora")
HotKeySet("^d", "Sdol")
HotKeySet("{F6}", "Search")
Global $LG = StringSplit("0,0", ",")
Global $PD = StringSplit("0,0", ",")
Global $kolory
Global $sspos
Global $wsp

While 1
    Sleep(50)
    $pos = MouseGetPos()
    TrayTip("Współrzędne", $pos[0] & "," & $pos[1], 10)

WEnd
;========================================================
Func Search()
    Szukaj($kolory, $wsp)
EndFunc
;========================================================
Func Szukaj( ByRef $substring, ByRef $new_poz)
    Local $string
    $new_poz = StringSplit("0,0", ",")
    For $sy = $LG[2] To $PD[2] Step 1
        For $sx = $LG[1] To $PD[1] Step 1
            $pixColor = PixelGetColor($sx, $sy)
            ToolTip($sx & ", " & $sy &": " & $pixColor)
            $string = $string & $pixColor
        Next
    Next
    ToolTip("")
    $result = StringInStr($string, $substring, 0, 1)
    If $result <> 0 And $result <> 1 Then
        Local $ile_pix = $result / 8
        Local $ile_w = Int($ile_pix / ($PD[1] - $LG[1]))
        Local $ile_k = Mod($ile_pix , $PD[1] - $LG[1])
        $new_poz[1] = $LG[1] + $ile_k + 12
        $new_poz[2] = $LG[2] + $ile_w
        $len = StringLen($string)
        MsgBox(0, "Szukanie", "result: " & $result & @CR & "new poz: " & $new_poz[1] & "," & $new_poz[2] & @CR & "ile_w: "& $ile_w & @CR & "ile_k: " & $ile_k & @CR & "dlug: " & $len)
    EndIf
    Return $new_poz
EndFunc ;==>Szukaj
;========================================================
Func GetPix($wspx, ByRef $pix)
    Local $string = ""
;Local $pix
    For $w = $wspx[1] - 12 To $wspx[1] + 12 Step 1
        Local $pixColor = PixelGetColor($w, $wspx[2])
        $string = $string & $pixColor
    Next
    $pix = $string
    Return $pix
EndFunc ;==>GetPix

Those are not important:
;========================================================
Func SSpos()
    $szukane = MouseGetPos()
    $wspS = StringSplit("0,0", ",")
    $wspS[1] = $szukane[0]
    $wspS[2] = $szukane[1]
    GetPix($wspS, $kolory)
EndFunc ;==>SSpos
;========================================================
Func Sgora()
    $sspos = MouseGetPos()
    $LG[1] = $sspos[0]
    $LG[2] = $sspos[1]
EndFunc ;==>Sgora
;========================================================
Func SDol()
    $sspos = MouseGetPos()
    $PD[1] = $sspos[0]
    $PD[2] = $sspos[1]
EndFunc ;==>SDol

1. When I'm reading pixels to $string it's length should be dividable by 8, but it's not always.

My coding is a bit messy, but I hope some of You will understand it :) At any doubts I'll explain my ideas.

$LG is top left corner of rectangle, $PD is right bottom corner

Edited by Bundy

Share this post


Link to post
Share on other sites



Have you tried changing this:

If $result <> 0 And $result <> 1 Then

To Just:

If $result Then

And Maybe comment this out:

Local $ile_k = Mod($ile_pix , $PD[1] - $LG[1])

If it still isn't working?

And Look at

$LG = StringSplit("0,0", ",")

Couldn't you just make those:

$LG[3]
?

Just a guess since no one had answered you yet...


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

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