HEX color to INT value

HEX color to INT value

Postby Otto » Tue Dec 25, 2018 7:16 pm

Hello,
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
********************************************************************
User avatar
Otto
 
Posts: 6346
Joined: Fri Oct 07, 2005 7:07 pm

Re: HEX color to INT value

Postby Silvio.Falconi » Tue Dec 25, 2018 7:50 pm

https://toolset.mrwebmaster.it/colori/hex-to-rgb.html
http://www.javascripter.net/faq/rgbtohex.htm


From manuel calero solis

Code: Select all  Expand view  RUN
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 November 2023 - January 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
User avatar
Silvio.Falconi
 
Posts: 7076
Joined: Thu Oct 18, 2012 7:17 pm

Re: HEX color to INT value

Postby nageswaragunupudi » Tue Dec 25, 2018 8:00 pm

If you have the color in the hex-format "#rrggbb"

then

nRGB( cHexClr ) --> nColor
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10662
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: HEX color to INT value

Postby Antonio Linares » Tue Dec 25, 2018 8:05 pm

There is also:

function nHex( cHex ) --> nValue
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42126
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: HEX color to INT value

Postby nageswaragunupudi » Tue Dec 25, 2018 8:14 pm

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.
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10662
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: HEX color to INT value

Postby Otto » Tue Dec 25, 2018 10:44 pm

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
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6346
Joined: Fri Oct 07, 2005 7:07 pm

Re: HEX color to INT value

Postby Giovany Vecchi » Wed Dec 26, 2018 12:35 am

OI Otto, I do not know if that's what you're looking for.

Code: Select all  Expand view  RUN

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
 
User avatar
Giovany Vecchi
 
Posts: 223
Joined: Mon Jun 05, 2006 9:39 pm
Location: Brasil

Re: HEX color to INT value

Postby nageswaragunupudi » Wed Dec 26, 2018 3:54 am

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 view  RUN
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
User avatar
nageswaragunupudi
 
Posts: 10662
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: HEX color to INT value

Postby Otto » Wed Dec 26, 2018 10:52 am

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

Image
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6346
Joined: Fri Oct 07, 2005 7:07 pm

Re: HEX color to INT value

Postby Otto » Wed Dec 26, 2018 11:10 am

Best regards
Otto

Image
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6346
Joined: Fri Oct 07, 2005 7:07 pm

Re: HEX color to INT value

Postby nageswaragunupudi » Wed Dec 26, 2018 11:36 am

Look Great
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10662
Joined: Sun Nov 19, 2006 5:22 am
Location: India


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 69 guests