; PIXEL RECT functions ; ; Functions: ;------------------------------------------------------------------------------- ; _LoadPixelRect( , , , ) ; ; Synopsis: Returns a 2-dimensional array of pixel colors from within ; the coordinates provided. ;------------------------------------------------------------------------------- ; _SavePixelRect( , ) ; ; Synopsis: Saves a 2-dimensional array into a comma delimited text file ;------------------------------------------------------------------------------- ; _LoadPixelRectFromFile( ) ; ; Synopsis: Populates a 2-dimensional array from a comma delimited text file ;------------------------------------------------------------------------------- ; _FindPixelRect( , , , , ) ; ; Synopsis: Searches a rectangle according to the coordinates provided ; for a rectangle of pixels provided as a 2-dimensional array. ; returns coordinates of the upper left pixel where found ;------------------------------------------------------------------------------- ; EXAMPLE: ; The following will get some pixels of the top left icon on the desktop ; $a = _LoadPixelRect(25,25,30,30) ; ; When the following MsgBox appears, move the icon to another position ; MsgBox(4096,"","") ; ; The following searches the desktop for that icon ; $a = _FindPixelRect(0,0,@DesktopWidth,@DesktopHeight,$a) ; ; If found, the following returns the pixel coordinates of the little rect previously loaded ; If Not @error Then MsgBox(4096,"Coordinates of your Rect", _ ; "Coordinates of your Rect: " & $a[0] & "," & $a[1]) ; ; Func _FindPixelRect($FPR_nL, $FPR_nT, $FPR_nR, $FPR_nB, ByRef $FPR_aPixRect) $FPR_nLimitX = UBound($FPR_aPixRect) $FPR_nLimitY = UBound($FPR_aPixRect, 2) If Not $FPR_nLimitX Or Not $FPR_nLimitY Then SetError(1) Return 0 EndIf $FPR_nLimitX = $FPR_nLimitX - 1 $FPR_nLimitY = $FPR_nLimitY - 1 If ($FPR_nL + $FPR_nLimitX) > $FPR_nR Or _ ($FPR_nT + $FPR_nLimitY) > $FPR_nB Then SetError(2) Return 0 EndIf $FPR_aCoord = PixelSearch($FPR_nL, $FPR_nT, $FPR_nR, $FPR_nB, $FPR_aPixRect[0][0]) While Not @error For $FPR_x = 0 to $FPR_nLimitX For $FPR_y = 0 to $FPR_nLimitY If $FPR_aPixRect[$FPR_x][$FPR_y] <> _ PixelColor($FPR_aCoord[0] + $FPR_x, $FPR_aCoord[1] + $FPR_y) Then SetError(1) ExitLoop 2 EndIf Next Next If Not @error Then Return $FPR_aCoord $FPR_aTEMP = PixelSearch($FPR_aCoord[0], $FPR_aCoord[1]+1, _ $FPR_aCoord[0], $FPR_nB, $FPR_aPixRect[0][0]) If @error Then $FPR_aCoord = PixelSearch($FPR_aCoord[0]+1, $FPR_nT, _ $FPR_nR, $FPR_nB, $FPR_aPixRect[0][0]) Else $FPR_aCoord = $FPR_aTEMP EndIf WEnd SetError(3) Return 0 EndFunc Func _LoadPixelRect($LPR_nL, $LPR_nT, $LPR_nR, $LPR_nB) If ($LPR_nL > $LPR_nR Or $LPR_nT > $LPR_nB) Then SetError(1) Return 0 EndIf Dim $LPR_aPixRect[($LPR_nR-$LPR_nL)+1][($LPR_nB-$LPR_nT)+1] For $LPR_nY = $LPR_nT To $LPR_nB For $LPR_nX = $LPR_nL To $LPR_nR $LPR_aPixRect[$LPR_nX-$LPR_nL][$LPR_nY-$LPR_nT] = PixelColor($LPR_nX,$LPR_nY) Next Next Return $LPR_aPixRect EndFunc Func _LoadPixelRectFromFile($LPRFF_szBuffer) If Not FileExists($LPRFF_szBuffer) Then SetError(1) Return 0 EndIf $LPRFF_szBuffer = StringStripCR(FileRead($LPRFF_szBuffer, FileGetSize($LPRFF_szBuffer))) If StringRight($LPRFF_szBuffer,1)== @LF Then _ $LPRFF_szBuffer = StringTrimRight($LPRFF_szBuffer,1) $LPRFF_szBuffer = StringSplit($LPRFF_szBuffer,@LF) $LPRFF_szLine = StringSplit($LPRFF_szBuffer[1],",") $LPRFF_nLimitX = $LPRFF_szLine[0] $LPRFF_nLIMITY = $LPRFF_szBuffer[0] Dim $LPRFF_aPixRect[$LPRFF_nLIMITY][$LPRFF_nLimitX] For $LPRFF_nY = 1 To $LPRFF_nLIMITY $LPRFF_szLine = StringSplit($LPRFF_szBuffer[$LPRFF_nY],",") If $LPRFF_szLine[0] <> $LPRFF_nLimitX Then SetError(1) Return 0 EndIf For $LPRFF_nX = 1 To $LPRFF_nLimitX $LPRFF_aPixRect[$LPRFF_nY-1][$LPRFF_nX-1] = Number($LPRFF_szLine[$LPRFF_nX]) Next Next Return $LPRFF_aPixRect EndFunc Func _SavePixelRect(ByRef $SPR_aRect, $SPR_szFile) Dim $SPR_szBuffer="" If Not IsArray($SPR_aRect) Or Not UBound($SPR_aRect, 2) Then SetError(1) Return 0 EndIf $SPR_nLimitY = UBound($SPR_aRect) $SPR_nLimitX = UBound($SPR_aRect,2) For $SPR_nY = 0 To $SPR_nLimitY-1 For $SPR_nX = 0 To $SPR_nLimitX-1 $SPR_szBuffer = $SPR_szBuffer & $SPR_aRect[$SPR_nY][$SPR_nX] & "," Next $SPR_szBuffer = StringTrimRight($SPR_szBuffer,1) & @CRLF Next $SPR_szBuffer = StringTrimRight($SPR_szBuffer,2) FileDelete($SPR_szFile) FileWrite($SPR_szFile,$SPR_szBuffer) Return 1 EndFunc Func PixelColor($x, $y) For $PC_i = 1 to 100 $a = PixelGetColor($x,$y) If Not @error Then Return $a Next SetError(1) Return -1 EndFunc