Page 1 of 1
HEX color to INT value
Posted: Tue Dec 25, 2018 7:16 pm
by Otto
Hello,
is there a function to change the color HEX value to an INT value.
Thank you in advance
Otto
Re: HEX color to INT value
Posted: Tue Dec 25, 2018 7:50 pm
by Silvio.Falconi
https://toolset.mrwebmaster.it/colori/hex-to-rgb.htmlhttp://www.javascripter.net/faq/rgbtohex.htmFrom
manuel calero solisCode: Select all | Expand
FUNCTION RgbToRgbHex( nColorRgb )
local cRgbHex := ""
cRgbHex += "#"
cRgbHex += NumToHex( nRgbRed( nColorRgb ), 2 )
cRgbHex += NumToHex( nRgbGreen( nColorRgb ), 2 )
cRgbHex += NumToHex( nRgbBlue( nColorRgb ), 2 )
RETURN cRgbHex
Re: HEX color to INT value
Posted: Tue Dec 25, 2018 8:00 pm
by nageswaragunupudi
If you have the color in the hex-format "#rrggbb"
then
nRGB( cHexClr ) --> nColor
Re: HEX color to INT value
Posted: Tue Dec 25, 2018 8:05 pm
by Antonio Linares
There is also:
function nHex( cHex ) --> nValue
Re: HEX color to INT value
Posted: Tue Dec 25, 2018 8:14 pm
by nageswaragunupudi
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.
Re: HEX color to INT value
Posted: Tue Dec 25, 2018 10:44 pm
by Otto
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
Re: HEX color to INT value
Posted: Wed Dec 26, 2018 12:35 am
by Giovany Vecchi
OI Otto, I do not know if that's what you're looking for.
Code: Select all | Expand
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
Re: HEX color to INT value
Posted: Wed Dec 26, 2018 3:54 am
by nageswaragunupudi
Mr. Otto
Do I only have to convert "BBGGRR" to "#RRGGBB"
Yes, exactly.
For your purpose, you can use the function RGB_TO_HTML() posted by Mr. Giovanny Vecchi or the function RgbToRgbHex() posted by Mr. Silvio.
You can also use this function:
Code: Select all | Expand
function CLRTOHTML( nClr )
local cHex := LOWER( NUMTOHEX( nClr, 6 ) )
return "#" + RIGHT( cHex, 2 ) + SUBSTR( cHex, 3, 2 ) + LEFT( cHex, 2 )
? CLRTOHTML( CLR_HRED ) // --> #ff0000
Re: HEX color to INT value
Posted: Wed Dec 26, 2018 10:52 am
by Otto
Dear Mr. Rao,
thank you for the function.
Now I have more or less my offline colors also in the PHP scheduler.
Best regards
Otto

Re: HEX color to INT value
Posted: Wed Dec 26, 2018 11:10 am
by Otto
Best regards
Otto

Re: HEX color to INT value
Posted: Wed Dec 26, 2018 11:36 am
by nageswaragunupudi
Look Great