Sign in to follow this  
Followers 0
DrCheeto

Issues witth PixelGetColor

5 posts in this topic

Hi as you should know the pixelgetcolor functions requires and x1/y1 and a x2/y2 which forms a box. This issue I am having is I want to find the position of multiple objects with the same color, but can not because it only retrieves the first pixel it finds, and starting at the position it found the last pixel doesn't work because it forms a box example.

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

xxxxxYxxxxxxxxxxxxxxxxxxxxxxxx

xxYxxxxxxxxxxxxxxxxxxxxxxxxxxx

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Say this is a bunch of pixels, after it found the first Y and if I started searching from that point, it would never find the other Y because now it has cut off every thing above and to the left of the first Y.

So I am not sure what I can do, but there has to be some support, I cant be the first person who wanted to find multiple objects with this.

The only other option i can think of is kinda grueling, where I literally make an x,y map and have a loop with the box only having a y of like 4.

Any help would be greatly appreciated.

Share this post


Link to post
Share on other sites



I use this to grab all the red in an image, you can certainly modify it to find whatever color you are looking for. Also in its current form it expects the capture area to be a perfect square.

#include <Array.au3>


Global $SAVEFILE = "c:\test\loading2.txt"
Global $IMAGE = "REDloading.bmp"


Dim $RED
Dim $ALL[1]
Dim $Columns[1]



$loading = _PicToArray($IMAGE, 400)

_findcolor ($loading, "FF0000")

_save($ALL , $SAVEFILE)



Func _findcolor ($SrcArray, $Color)

For $i = 0 TO Ubound ($SrcArray) - 1
$RED = _ArrayFindAll ($SrcArray , $Color , 0 , 0 ,0 ,1, $i)

For $k = 0 to ubound ($RED) - 1
    _ArrayAdd ($Columns , $i)
    Next

_ArrayConcatenate ($ALL , $RED)
Next

EndFUnc



Func _PicToArray($pic, $size)
    Dim $BArray[$size][$size]
SplashImageOn("", $pic , $size, $size, 0, 0, 1)
For $B = 0 To ubound ($BArray, 1) - 1
    For $C = 0 To ubound ($BArray, 2) - 1
        $BArray[$B][$C] = "0x" & Hex(PixelGetColor($B + 1, $C + 1), 6)
    Next
Next
splashoff ()
Return $BArray
EndFunc


Func _save($SrcArray , $FileName)
$pixFile = fileopen ($FileName , 2)

For $i = 1 to ubound ($All) - 1
    filewriteline ($pixFile , $Columns[$i])
        filewriteline ($pixFile , $ALL[$i])
    Next

FileClose ($pixFile)
EndFunc

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Share this post


Link to post
Share on other sites

Aight well I am looking for all of the color in an image, its not a file, its getting the pixels from a game screen.

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Let me correct myself;

Aight well I am looking for all of the color in an image, its not a file I can download, its getting the pixels from a website image, this image can change so there is no way to download it.

And here is what I have come up with so far, but it will do the first like 30 rows in a split second, then after that takes like 40+ sec per row and I am not sure why.

for $ncount = 751 to 978 step 2
    $tmp = 22
    $dr = 0
    while ($dr <> 1)
        if $tmp > 300 then
            $dr = 1
        endif
        $Coords = PixelSearch($tmp, $ncount, 259, $ncount, 0x7EBFF1)
        if isarray($coords) = true then
            $cods = PixelSearch($coords[0]+3, $ncount, $coords[0]+3, $ncount, 0x7EBFF1)
            if isarray($cods) Then
                $tmp = $coords[0]+20
                $arct += 2
                $places[$arct -2] = $coords[0]
                $places[$arct -1] = $coords[1]
                mousemove($coords[0],$coords[1])
                sleep(300)
            endif
        Else
            $dr = 1
        endif
    wend
    if mod(($ncount-1),10) = 0 Then
        MsgBox(0,"lol",$nCount)
    endif
next
Edited by DrCheeto

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