Function Reference

PixelSearch

Searches a rectangle of pixels for the pixel color provided.

PixelSearch ( left, top, right, bottom, color [, shade-variation] [, step]] )

 

Parameters

left left coordinate of rectangle.
top top coordinate of rectangle.
right right coordinate of rectangle.
bottom bottom coordinate of rectangle.
colour Colour value of pixel to find (in decimal or hex).
shade-variation [optional] A number between 0 and 255 to indicate the allowed number of shades of variation of the red, green, and blue components of the colour. Default is 0 (exact match).
step [optional] Instead of searching each pixel use a value larger than 1 to skip pixels (for speed). E.g. A value of 2 will only check every other pixel. Default is 1.

 

Return Value

Success: Returns a two-element array of pixel's coordinates. (Array[0] = x, Array[1] = y)
Failure: Sets @error to 1 if color is not found.

 

Remarks

The search is performed top-to-bottom, left-to-right, and the first match is returned.

Earlier versions of AutoIt (prior to v3.0.102) used the BGR format for defining color - newer versions use RGB by default but this can be changed using the ColorMode option.

Performing a search of a region can be time consuming, so use the smallest region you are able to reduce CPU load.

 

Related

ColorMode (Option), PixelChecksum, PixelGetColor, PixelCoordMode (Option)

 

Example


; Find a pure red pixel in the range 0,0-20,300
$coord = PixelSearch( 0, 0, 20, 300, 0xFF0000 )
If Not @error Then
    MsgBox(0, "X and Y are:", $coord[0] & "," & $coord[1])
EndIf


; Find a pure red pixel or a red pixel within 10 shades variations of pure red
$coord = PixelSearch( 0, 0, 20, 300, 0xFF0000, 10 )
If Not @error Then
    MsgBox(0, "X and Y are:", $coord[0] & "," & $coord[1])
EndIf