Sign in to follow this  
Followers 0
cppman

Red-Green-Blue

1 post in this topic

Here are some UDF's i thought might be helpful to some people.

;===============================================================================
;
; Description:      Converts 3 color values(red, green, blue) into a hex value.
; Syntax:           _RGBToHex($red_value, $green_value, $blue_value)
; Parameter(s):     $red_value - 0 - 255 RED.
;                   $green_value - 0 - 255 GREEN.
;                   $blue_value - 0 - 255 BLUE.
; Requirement(s):   None
; Return Value(s):  On Success - Returns the Hexadecimal value for the RGB color.
; Author(s):        Chris95219 <chris95219@gmail.com>
; Note(s):          None.
;
;===============================================================================
Func _RGBToHex($red_add, $green_add, $blue_add)
    $NEW =   Hex( $red_add ) & Hex( $green_add ) & Hex( $blue_add )
    $RED = StringTrimRight(StringTrimLeft($new, 6), 16)
    $GREEN = StringTrimRight(StringTrimLeft($new, 14), 8)
    $BLUE = StringTrimLeft($NEW, StringLen($NEW)-2)
    Return '0x' & $RED & $GREEN & $BLUE
EndFunc

;===============================================================================
;
; Description:      Converts a hexadecimal into its corresponding RGB values.
; Syntax:           _HexToRGB($color)
; Parameter(s):     $color - Hex value.
; Requirement(s):   must be a 6 digit hex color. e.g. 0xFF00CC
; Return Value(s):  On Success - Returns an array of 3 rgb values. [0] = red, [1] = green, [2] = blue.
; Author(s):        Chris95219 <chris95219@gmail.com>
; Note(s):          None.
;
;===============================================================================
Func _HexToRGB($color)
    $base           = StringSplit(Hex($color, 6), "")
            $RED    = Dec( $base[1]&$base[2] )
            $GREEN  = Dec( $base[3]&$base[4] )
            $BLUE   = Dec( $base[5]&$base[6] )
            
    Local   $avColors[3]
            $avColors[0] = $RED
            $avColors[1] = $GREEN
            $avColors[2] = $BLUE
    Return  $avColors
EndFunc

use _RGBToHex() to convert your RGB values to a hexidecimal value

use _HexTORGB() to convert your hex value to 3 RGB values.

:)

Share this post


Link to post
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
Sign in to follow this  
Followers 0