HEX color to INT value
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
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
********************************************************************
- Silvio.Falconi
- Posts: 4956
- Joined: Thu Oct 18, 2012 7:17 pm
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
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.
I use : FiveWin for Harbour August 2020 (Revision) - Harbour 3.2.0dev (r1712141320) - Bcc7.30 - xMate ver. 1.15.3 - PellesC
- nageswaragunupudi
- Posts: 8017
- Joined: Sun Nov 19, 2006 5:22 am
- Location: India
- 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: 37481
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Contact:
Re: HEX color to INT value
There is also:
function nHex( cHex ) --> nValue
function nHex( cHex ) --> nValue
- nageswaragunupudi
- Posts: 8017
- Joined: Sun Nov 19, 2006 5:22 am
- Location: India
- 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
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
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
********************************************************************
- Giovany Vecchi
- Posts: 129
- 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
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: 8017
- Joined: Sun Nov 19, 2006 5:22 am
- Location: India
- Contact:
Re: HEX color to INT value
Mr. Otto
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
Yes, exactly.Do I only have to convert "BBGGRR" to "#RRGGBB"
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
function CLRTOHTML( nClr )
local cHex := LOWER( NUMTOHEX( nClr, 6 ) )
return "#" + RIGHT( cHex, 2 ) + SUBSTR( cHex, 3, 2 ) + LEFT( cHex, 2 )
Regards
G. N. Rao.
Hyderabad, India
G. N. Rao.
Hyderabad, India
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
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
********************************************************************
Re: HEX color to INT value
Best regards
Otto
Otto
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
********************************************************************
- nageswaragunupudi
- Posts: 8017
- Joined: Sun Nov 19, 2006 5:22 am
- Location: India
- Contact: