_PixelSearchRightToLeft

  • Hallo,

    Ich wollte eine UDF für TimBlo machen, die es ermöglicht das PixelSearch von Rechts nach Links sucht.
    Nur es klappt einfach nicht, es kommt kein Rückgabewert, einfach nichts.

    Guckt euch einfach mal die UDF an:

    [autoit]

    Func _PixelSearchRightToLeft($iLeft, $iTop, $iRight, $iBottom, $hColour, $iShadeVariation = 0, $iStep = 1)
    Local $p_Search
    Local $i_Left = $iLeft, $i_Right = $iRight, $i_Bottom = $iBottom - 1
    Local $bTrue = False

    [/autoit][autoit][/autoit][autoit]

    If Not IsInt($iLeft) Or Not IsInt($iTop) Or Not IsInt($iRight) Or Not IsInt($iBottom) Or Not StringLen($hColour) = 8 Then
    Return 0
    EndIf

    [/autoit][autoit][/autoit][autoit]

    Do
    If $bTrue = False Then
    $p_Search = PixelSearch($i_Right, $iTop, $i_Right - 1, $i_Bottom - $iTop, $hColour, $iShadeVariation, $iStep)
    ElseIf $bTrue = True Then
    If $i_Right = $iLeft Then
    $i_Right = $iRight
    $p_Search = PixelSearch($i_Right, $iTop, $i_Right, $i_Bottom - $iTop, $hColour, $iShadeVariation, $iStep)
    EndIf
    EndIf

    [/autoit][autoit][/autoit][autoit]

    If $i_Right = $iLeft Then
    $i_Bottom -= 1
    EndIf
    $i_Left += 1
    $i_Right += 1
    $i_Bottom -= 1
    $bTrue = True
    Until IsArray($p_Search)

    [/autoit][autoit][/autoit][autoit]

    Return $p_Search
    EndFunc

    [/autoit]

    Hier ist die Demo:

    [autoit]

    HotKeySet("!e", "_Exit")

    [/autoit][autoit][/autoit][autoit]

    While 1
    $Search = _PixelSearchRightToLeft(0, 0, @DesktopWidth, @DesktopHeight, 0xFFFFFF)
    If $Search = 0 Then
    MsgBox(0, "Fail", "Fail")
    ElseIf IsArray($Search) Then
    MouseMove($Search[0], $Search[1], 0)
    EndIf
    WEnd

    [/autoit][autoit][/autoit][autoit]

    Func _Exit()
    Exit
    EndFunc

    [/autoit]

    Würde mich freuen wenn ihr mir helfen könntet :)

    • Offizieller Beitrag

    Viel zu kompliziert ;)
    Ganz kurz und einfach:

    [autoit]

    Func _PixelSearchRTL($left, $top, $right, $bottom, $color, $shVar=0, $step=1, $hWnd=0)
    If $hWnd = 0 Then $hWnd = WinGetHandle('[active]')
    If $step <> 1 Then $step = 1
    Local $ret
    For $i = $right To $left+1 Step -1
    $ret = PixelSearch($i-1, $top, $i, $bottom, $color, $shVar, $step, $hWnd)
    If Not @error Then Return $ret
    Next
    Return SetError(1,0,0)
    EndFunc

    [/autoit]

    Edit: Kleine Ergänzung, damit der User $step nicht ungleich 1 wählen kann. Die Funktion basiert ja darauf, dass jeweils ein 1 Pixel breiter Streifen, rechts beginnend bis zum angegebenen $left, abgefragt wird.

  • OOOOOOOOOOOKKKKKKKK.

    Das haut mich jetzt echt um...
    Hast du ja schon die UDF :)

    Ich sende mal die UDF an TimBlo mit der URL von diesem Thread ;)

  • Hab das auch mal getestet, nur ist das ganze viel zu langsam.

    Spoiler anzeigen
    [autoit]

    Local $start = TimerInit()
    $Pos = PixelSearch(61, 45, 1130, 353, 0x0, 0, 2)
    If IsArray($Pos) Then ConsoleWrite("PixelSearch: " & $Pos[0] & "/" & $Pos[1] & " " & TimerDiff($start) & @LF)

    [/autoit] [autoit][/autoit] [autoit]

    Local $start = TimerInit()
    $Pos = _PixelSearchReverse(61, 45, 1130, 353, 0x0, 0, 2)
    If IsArray($Pos) Then ConsoleWrite("PixelSearchReverse: " & $Pos[0] & "/" & $Pos[1] & " " & TimerDiff($start) & @LF)

    [/autoit] [autoit][/autoit] [autoit]

    Func _PixelSearchReverse($left, $top, $right, $bottom, $color , $shade = 0, $step = 1, $hwnd = "")
    Local $nColor, $aRet[2]
    For $y = $bottom To $top Step -$step
    For $x = $right To $left Step -$step
    $nColor = PixelGetColor($x, $y, $hwnd)
    If $nColor = $color Then
    $aRet[0] = $x
    $aRet[1] = $y
    Return $aRet
    EndIf
    Next
    Next
    Return SetError(1)
    EndFunc

    [/autoit]
    • Offizieller Beitrag

    Aus der Hilfe zur PixelSearch aus der Beta:

    Zitat

    Remarks

    The search direction varies as follows:
    Left-to-Right - left < right
    Right-to-Left - right < left
    Top-to-Bottom - top < bottom
    Bottom-to-Top - bottom < top
    Changing the search direction can be a useful optimization if the color being searched for frequently appears in in a specific quandrat of the search area since less searching is done if the search starts in the most common quadrant.

    Remember, a typical display at 1024 x 768 has 786432 pixels. Although PixelSearch is optimized, narrowing the search area helps speed up the result.

  • ich glaube raupi hat gerad das gesagt was ich wollte...
    wäre es nicht einfacher die Parameter zu drehen?, also
    PixelSearch($rechts, $unten, $links, $oben, $farbe, $shadevar, $step*-1)
    kann das nicht funktionieren??

    Dies ist ein Arzeneimittel.
    Bei Risiken und Haluzinationen fressen sie die Packungsbeilage und schlagen Sie ihren Arzt oder Apotheker.
    Jede Haftung wird abgelent.

    Vielen Dank für Ihre Kundentreue.
    mfg. TimBlo

    Aperture Science

    http://www.youtube.com/watch?v=Y6ljFaKRTrI