Jump to content

I need script help


Recommended Posts

I want to make a function with in a script that will scan a specific square area with in the screen and return a count of the amount of pixels in that area containing a specific color. I am very new to this and understand how to use the PixelSearch. But I don't understand how to loop it in order to acheive what I want.

Thanks in advance,

Newb

Link to comment
Share on other sites

Try something like

for $x = $xstart to $xend
    for $y = $ystart to $yend
        if pixelgetcolor($x, $y) = $color then $count = $count + 1
    next
next

where $xstart, $xend, $ystart, $yend are used to decide which rectangle of pixels to check, $color is the color you are looking for, and $count is used to record how many match. I did not test the code, but this is the general idea.

Link to comment
Share on other sites

  • Moderators

Try something like

for $x = $xstart to $xend
    for $y = $ystart to $yend
        if pixelgetcolor($x, $y) = $color then $count = $count + 1
    next
next

where $xstart, $xend, $ystart, $yend are used to decide which rectangle of pixels to check, $color is the color you are looking for, and $count is used to record how many match. I did not test the code, but this is the general idea.

Nice Usage there Squid, should make that to a UDF for them :lmao: !!

Edit: Here you go, using your idea ;)

Dim $Window = 'Text of title of window to search'
_PixelGetCount(0, 100, 0, 100, 0xFF0000, $Window)

Func _PixelGetCount($xstart, $xend, $ystart, $yend, $c_Color, $w_Window = '')
    Local $count = ''
    For $x = $xstart to $xend
        For $y = $ystart to $yend
            If $w_Window <> '' Then
                If Not WinActive($w_Window) Then WinActivate($w_Window)
            EndIf
            If PixelGetColor($x, $y) = $c_Color Then $count = $count + 1
        Next
    Next
Return $count
EndFunc
Edited by SmOke_N

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.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...