HEX color to INT value
- Otto
- Posts: 6413
- Joined: Fri Oct 07, 2005 7:07 pm
- Has thanked: 28 times
- Been thanked: 2 times
- Contact:
HEX color to INT value
Hello,
is there a function to change the color HEX value to an INT value.
Thank you in advance
Otto
is there a function to change the color HEX value to an INT value.
Thank you in advance
Otto
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
- Silvio.Falconi
- Posts: 7164
- Joined: Thu Oct 18, 2012 7:17 pm
- Been thanked: 2 times
Re: HEX color to INT value
https://toolset.mrwebmaster.it/colori/hex-to-rgb.html
http://www.javascripter.net/faq/rgbtohex.htm
From manuel calero solis
http://www.javascripter.net/faq/rgbtohex.htm
From manuel calero solis
Code: 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
Last edited by Silvio.Falconi on Tue Dec 25, 2018 8:02 pm, edited 1 time in total.
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
- nageswaragunupudi
- Posts: 10729
- Joined: Sun Nov 19, 2006 5:22 am
- Location: India
- Been thanked: 10 times
- Contact:
Re: HEX color to INT value
If you have the color in the hex-format "#rrggbb"
then
nRGB( cHexClr ) --> nColor
then
nRGB( cHexClr ) --> nColor
Regards
G. N. Rao.
Hyderabad, India
G. N. Rao.
Hyderabad, India
- Antonio Linares
- Site Admin
- Posts: 42597
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Has thanked: 40 times
- Been thanked: 86 times
- Contact:
- nageswaragunupudi
- Posts: 10729
- Joined: Sun Nov 19, 2006 5:22 am
- Location: India
- Been thanked: 10 times
- Contact:
Re: HEX color to INT value
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.
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.
Regards
G. N. Rao.
Hyderabad, India
G. N. Rao.
Hyderabad, India
- Otto
- Posts: 6413
- Joined: Fri Oct 07, 2005 7:07 pm
- Has thanked: 28 times
- Been thanked: 2 times
- Contact:
Re: HEX color to INT value
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
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
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
- Giovany Vecchi
- Posts: 223
- Joined: Mon Jun 05, 2006 9:39 pm
- Location: Brasil
Re: HEX color to INT value
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
- nageswaragunupudi
- Posts: 10729
- Joined: Sun Nov 19, 2006 5:22 am
- Location: India
- Been thanked: 10 times
- Contact:
Re: HEX color to INT value
Mr. Otto
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:
? CLRTOHTML( CLR_HRED ) // --> #ff0000
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
Regards
G. N. Rao.
Hyderabad, India
G. N. Rao.
Hyderabad, India
- Otto
- Posts: 6413
- Joined: Fri Oct 07, 2005 7:07 pm
- Has thanked: 28 times
- Been thanked: 2 times
- Contact:
Re: HEX color to INT value
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

thank you for the function.
Now I have more or less my offline colors also in the PHP scheduler.
Best regards
Otto

********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
- Otto
- Posts: 6413
- Joined: Fri Oct 07, 2005 7:07 pm
- Has thanked: 28 times
- Been thanked: 2 times
- Contact:
Re: HEX color to INT value
Best regards
Otto

Otto

********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
- nageswaragunupudi
- Posts: 10729
- Joined: Sun Nov 19, 2006 5:22 am
- Location: India
- Been thanked: 10 times
- Contact: