Jump to content

Array help


Recommended Posts

I have a image(bmp) that i want to scan for 1 pixel that might show more than once. I want to store all the results in a array after scan completes, then click all the pixels and removes the array for that 1 click untill the array empyties. How can I do this ?

Thought that this might be easy but guess was wrong :blink:

Link to comment
Share on other sites

I have the following code for checking the bmp file but it won't find the colour :blink: any ideas?

$img = @MyDocumentsDir & "\GDIPlus_Image1.jpg"
$hImage = _GDIPlus_ImageLoadFromFile ($img)
$hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap ($hImage)
$width = _GDIPlus_ImageGetWidth($hImage)
$height = _GDIPlus_ImageGetHeight($hImage)
$colour = 0xEAFCBE
$coord = PixelSearch(0, 0, $width-1, $height-1, $colour, 0, 300, $hBitmap)
If @error Then
        ToolTip("No colours", 0 ,0)
        Else
        For $x = 1 to $coord
                ToolTip("array" & $coord[0] & $coord[1], 0 ,0)
        sleep (2000)
        Next
EndIf
Link to comment
Share on other sites

Firstly, PixelSearch ends when it finds the first intance of the colour as far as I know.

Secondly, I dont think the base of an array holds a value ($coord) only the array elements hold values, perhaps you are looking for Ubound($coords).

Thirdly, I'm not convinced you can use Pixelsearch in that manner, it uses a window handle, and creates its own bitmap I think.

I know this isnt helping you (I dont know how to do a recursive pixelsearch (if thats even a thing), but it will give you something to think about.

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

It would take a bit of coding.

If your picture was on screen and small, I would just do some pixelgetcolor() on each pixel and store it into an array, then loop through that array.

if it were on screen and huge, I would perfom my pixelsearch line by line.

0>1>2>3>4x5>6>7>8>9>

0>1x2>3>4>5>6>7>8>9>

0>1>2>3>4>5>6>7x8>9>

say the ">" are pixels that are not your color and "x" are your colour.

You would pixelsearch the first row from 0 to 9, when the pixelsearch returns at 4, you would start a new on from 5 to 9, then continue another at the second row from 0 to nine and so on.

Its a few loops, if thens, and suchlike.

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

Thats 1 way of doing it but think it might be a bit to slow :blink: Found a script that oflight coded I think, would this work?

;=================================   PixelFindAll   ==============================
; Function Name:    _PixelFindAll
; Description:      Finds all instances of a pixel within a given area and returns array with Total and all locations X and Y.
;                   Allows you to limit results by skiping pixels within a given distance to each other.
; Requires:                         None
; Parameters:       $Pixel          Colour value of pixel to find (in decimal or hex).
;                   $XDist          Horizontal distance from found pixel to skip before continueing search (moving right)
;                   $YDist          Vertical distance from found pixel to skip before continueing search (moving down)
;                   $sv             Shade Varience
;                   $SB_l           left coordinate of total area to search. Default is 0 (far left side of screen)
;                   $SB_t           top coordinate of total area to search. Default is 0 (top most Side of screen)
;                   $SB_r           Right coordinate of total area to search. Default is @DesktopWidth (Far Right side of screen)
;                   $SB_b           Bottom coordinate of total area to search. Default is @DesktopHeight (Bottom most side of screen)
; Syntax:         _PixelFindAll($pixel[, $XDist, $YDist, $sv, $SB_l, $SB_t, $SB_r, $SB_b])
; Author(s):    
; Returns:      $Array[0][0] = 0 on failure
;===============================================================================
Func _PixelFindAll($pixel,$XDist=0,$YDist=0,$sv=0,$SB_l=0,$SB_t=0,$SB_r=@DesktopWidth,$SB_b=@DesktopHeight)
    Dim $Array[2][2], $Count = "0", $SB_l_Max = $SB_l, $SB_b_Max = $SB_b
    $Array[0][0] = "0"

    While 1
        $xy = PixelSearch($SB_l,$SB_t,$SB_r,$SB_b,$pixel,$sv)
        If @error And $SB_b = $SB_b_Max Then
            SetError(1)
            
            Dim $Array2[2][2]
            $Array2[0][0] = "0"
            $Count = "0"

            For $i = 1 to $Array[0][0]
                $Write = 1              
                For $j = $i+1 to $Array[0][0]
                    $VarX = _CompareNumbers($Array[$i][0], $Array[$j][0], $XDist)
                    If $VarX = 0 Then
                        $VarY = _CompareNumbers($Array[$i][1], $Array[$j][1], $YDist)
                        If $VarY = 0 Then $Write = 0
                    EndIf
                Next
                If $Write = 1 Then
                    $Count = $Count+1
                    $Array2[0][0] = $Count
                    ReDim $Array2[$Count+1][2]
                        $Array2[$Count][0] = $Array[$i][0]
                        $Array2[$Count][1] = $Array[$i][1]              
                EndIf
            Next

            Return $Array2
        ElseIf @error Then
            $SB_t = $SB_b + 1
            $SB_b = $SB_b_Max
            $SB_l = $SB_l_Max
        Else
            $Count = $Count+1
            $Array[0][0] = $Count
            ReDim $Array[$Count+1][2]
            $Array[$Count][0] = $xy[0]
            $Array[$Count][1] = $xy[1]

            $SB_t = $xy[1]
            $SB_b = $SB_t
            $SB_l = $xy[0]+1+$YDist 
        EndIf
    WEnd
EndFunc;==========================  PixelFindAll   ===============================

Func _CompareNumbers($Number1, $Number2, $byhowmuch);SUB Function of PixelFindAll
    ;Verify that $Number1 is more than $byhowmuch from $Number2
    ;Returns 0 if within $byhowmuch
    If $Number1 = $Number2 Then
        Return 0
    ElseIf $Number1 > $Number2 Then
        If ($Number1-$byhowmuch) >= $Number2 Then Return 1
    ElseIf $Number1 < $Number2 Then
        If ($Number1+$byhowmuch) <= $Number2 Then Return 1
    EndIf
    Return 0
EndFunc
Link to comment
Share on other sites

Im trying this but it won't write the postitions to the ini file any ideas?

$i = 0
$colour = 0xFF710C
$TotalSearches = 0 ;For testing speed only

While 1
    $coord1 = _PixelFindAll($colour,0,0,0,0,@DesktopWidth,@DesktopHeight)
    If Not @error Then
        IniWrite(".\Pixel.ini","Main","PixelPos",$coord1)
    $TotalSearches = $TotalSearches+1 ;For testing speed only
    tOOLTIP($TotalSearches)           ;For testing speed only
    EndIf
WEnd
Link to comment
Share on other sites

#include <Array.au3>

$i = 0
$colour = 0xFF710C
$TotalSearches = 0 ;For testing speed only

While 1
    $coord1 = _PixelFindAll($colour,0,0,0,0,@DesktopWidth,@DesktopHeight)
    If Not @error Then
        _ArrayDisplay($coord1)
        IniWrite(".\Pixel.ini","Main","PixelPos",$coord1)
    $TotalSearches = $TotalSearches+1 ;For testing speed only
    tOOLTIP($TotalSearches)           ;For testing speed only
    Else
        MsgBox(0,"Error","error")
    EndIf
WEnd

What are the results?

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

Ironically You just missed a Zero :blink:

8 inputes to fully specify a searchbox.

_PixelFindAll($pixel[, $XDist, $YDist, $sv, $SB_l, $SB_t, $SB_r, $SB_b])

#include <Array.au3>


$colour = 16777118

$coord1 = _PixelFindAll($colour,0,0,0,0,0,@DesktopWidth,@DesktopHeight)
If IsArray($coord1) Then
    _ArrayDisplay($coord1)
    For $i = 1 to $coord1[0][0]
        IniWrite(".\Pixel.ini","Main","X_PixelPos_"&$i,$coord1[$i][0])
        IniWrite(".\Pixel.ini","Main","Y_PixelPos_"&$i,$coord1[$i][1])
    Next
Else
    MsgBox(0,"Error","error")
EndIf

Edit: forgot to test the ini write part, muh bad ;)

Edited by ofLight

There is always a butthead in the crowd, no matter how hard one tries to keep them out.......Volly

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...