KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Converting a 4D color to an SVG compatible RGB string
PRODUCT: 4D | VERSION: 11 | PLATFORM: Mac & Win
Published On: August 6, 2009

The Tech Tip Converting from 4D's color palette to RGB creates an RGB longint value (0x00RRGGBB) from a 4D color index (1-256). If you are working with 4D SVG, an RGB string becomes useful. The following code will convert that longint value into an SVG comptible RGB string:

`Util_RGBToRGBString( RGB_L ) -> RGB_T
C_TEXT($0;$RGBStr_T)
C_LONGINT($RGB_L;$1)
C_LONGINT($RGB_L;$Red_L;$Green_L;$Blue_L)

$RGB_L:=$1

` Get the individual RGB values.
$Red_L:=(($RGB_L >> 16) & 0x00FF) ` get the red byte, 0..255
$Green_L:=(($RGB_L >> 8) & 0x00FF) ` get the green byte, 0..255
$Blue_L:=($RGB_L & 0x00FF) ` get the blue byte, 0..255

$RGBStr_T:="rgb("+String($Red_L)+","+String($Green_L)+","+String($Blue_L)+")"

$0:=$RGBStr_T


To use that method the RGB longint value would have to be retrieved first. The following code uses the method from Converting from 4D's color palette to RGB to get that value and then calls the above method to turn it into text.

C_LONGINT($ColorNdx_L;$RGB_L)
C_TEXT($RGB_T)

$ColorNdx_L:=122 ` Any value from 1-256
$RGB_L:=Util_ColorIndexToRGB( $ColorNdx_L )
$RGB_T:=Util_RGBToRGBString( $RGB_L )


See Also: