Core Function PixelSearch
PixelSearch ( <left>, <top>, <right>, <bottom>, <colour>, <shade>, <padding>, <step> )
Contents |
Description
Searches a rectangle of pixels for the pixel colour provided.
Parameters
left
left coordinate of rectangle.
top
top coordinate of rectangle.
right
right coordinate of rectangle.
bottom
bottom coordinate of rectangle.
colour
Optional but recommended!; Colour value of pixel to find (in decimal or hex).
NOTE - If you not specify a colour value every pixel in your search Rect will be returned as an array see remarks.
shade
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).
padding
Optional; A range of pixels to search around any *found* pixels for example a pad of 1 will cause an area of like 2x2x2 to be scanned instead of just the 1 pixel.
Default is 0 (no padding).
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: Returns empty array.
Remarks
The search is performed top-to-bottom, left-to-right, and the first match is returned.
RGB is used to define colours by default but this can be changed using the ColourMode option.
Performing a search of a region can be time consuming, so use the smallest region you are able to reduce CPU load.
Note a search of "74, 101, 640, 480" does not mean start at 74x101 and scan a range of 640x480 pixels it means start the rect at 74x101 and stop the rect at 640x480.
See "PixelCoordMode" in Opt
Example
$coord = PixelSearch( 35, 99, 600, 600, 0x0000ff ); If ( $coord ) { MsgBox("X and Y are: $coord[0] , $coord[1]"); } Else { MsgBox("not found"); } // OR List ($x, $y) = PixelSearch( 35, 99, 600, 600, 0x0000ff ); If ( $x && $y ) // It is true this will fail a match at coordinate 0,0 but its unlikely that it would matter { MsgBox("X and Y are: $x, $y"); } Else { MsgBox("not found"); }
If you do not specify a colour value every pixel in your search Rect will be returned as an array see this example:
$target = PixelSearch ( 0, 0, 100, 100 ); foreach($target as $i) { List( $X, $Y, $Red, $Green, $Blue ) = $i; println("X '$X' Y '$Y,' Red '$Red' Green '$Green' Blue '$Blue'"); } println($target); // You could do this to do your own scan on the pixels // however doing this can be very slow on large rects // Note - The $X and $Y is relative to the search rect // so it will start at 0,0 if you want to get absolute // coordinates you will need to add the required numbers // Like this: List( $X, $Y, $Red, $Green, $Blue ) = $i; $X += 30; $Y += 30;