Skip to content

Instantly share code, notes, and snippets.

Created October 24, 2013 11:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/7135317 to your computer and use it in GitHub Desktop.
Save anonymous/7135317 to your computer and use it in GitHub Desktop.
; #FUNCTION# ======================================================================================
; Name...........: _ColorSetRGB
; Description ...: Returns the RGB color to work with (COLORREF).
; Syntax.........: _ColorSetRGB($aColor)
; Parameters ....: $aColor - an array of values in the range 0-255:
; [0] Red component color
; [1] Green component color
; [2] Blue component color
; Return values .: Success - returns the RGB color to work with (hexadecimal code).
; Failure - set @error to:
; @error - 1 invalid array
; 2 invalid color value
; Author ........: jpm
; Modified.......:
; Remarks .......: @extended is preserved
; Related .......: _ColorGetRGB
; Link ..........:
; Example .......:
; =================================================================================================
Func _ColorSetRGB($aColor, $curExt = @extended)
If UBound($aColor) <> 3 Then Return SetError(1, 0, -1) ; invalid array
Local $nColor = 0, $iColor
For $i = 0 To 2
$nColor = BitShift($nColor, -8)
$iColor = $aColor[$i]
If $iColor < 0 Or $iColor > 255 Then Return SetError(2, 0, -1) ; invalid color value
$nColor += $iColor
Next
Return SetExtended($curExt, $nColor)
EndFunc ;==>_ColorSetRGB
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment