Hello,
is there a function to change the color HEX value to an INT value.
Thank you in advance
Otto
Hello,
is there a function to change the color HEX value to an INT value.
Thank you in advance
Otto
FUNCTION RgbToRgbHex( nColorRgb )
local cRgbHex := ""
cRgbHex += "#"
cRgbHex += NumToHex( nRgbRed( nColorRgb ), 2 )
cRgbHex += NumToHex( nRgbGreen( nColorRgb ), 2 )
cRgbHex += NumToHex( nRgbBlue( nColorRgb ), 2 )
RETURN cRgbHexIf you have the color in the hex-format "#rrggbb"
then
nRGB( cHexClr ) --> nColor
There is also:
function nHex( cHex ) --> nValue
The difference is this:
Windows COLORREF constants, when expressed in hex are 0xBBGGRR
If we have such a color string "BBGGRR"
then nHex( cHex ) or HEXTONUM( cHex ) would convert the hex string to numeric value.
Mostly in web and other platforms colors are expressed as "#RRGGBB"
In such cases nHex( cHex ) or HEXTONUM( cHex ) do not give the correct color constant.
nRGB( cHexClr ) gives the correct color constant.
What is important is the source of cHex Mr Otto is referring to.
Dear Mr. Rao, dear Antonio,
I am sorry I asked the wrong way.
I have the INT value, for example: 16711680 and I need the HEX value: #0000ff
NumToHex(16711680 ) gives #ff0000.
Do I only have to convert "BBGGRR" to "#RRGGBB".
Best regards
Otto
FUNCTION RGB_TO_HTML(f_nColor)
Local cColorReturn := "#", aTmpRGB := {}
aadd(aTmpRGB,decToHex(nRGBRed(f_nColor)))
aadd(aTmpRGB,decToHex(nRGBgreen(f_nColor)))
aadd(aTmpRGB,decToHex(nRGBBlue(f_nColor)))
If Len(aTmpRGB[1]) == 1
aTmpRGB[1] := "0"+aTmpRGB[1]
EndIf
If Len(aTmpRGB[2]) == 1
aTmpRGB[2] := "0"+aTmpRGB[2]
EndIf
If Len(aTmpRGB[3]) == 1
aTmpRGB[3] := "0"+aTmpRGB[3]
EndIf
cColorReturn += (aTmpRGB[1]+aTmpRGB[2]+aTmpRGB[3])
Return cColorReturn
Do I only have to convert "BBGGRR" to "#RRGGBB"
function CLRTOHTML( nClr )
  local cHex  := LOWER( NUMTOHEX( nClr, 6 ) )
return "#" + RIGHT( cHex, 2 ) + SUBSTR( cHex, 3, 2 ) + LEFT( cHex, 2 )

Look Great