FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Color format
Posts: 1392
Joined: Mon May 14, 2007 09:49 AM

Color format

Posted: Tue Jun 24, 2025 05:43 AM

For example, the orange color is RGB(255, 69, 0) or #FF4500.

How can I recalculate the RGB value to #FF4500?

Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM

Re: Color format

Posted: Tue Jun 24, 2025 05:59 AM
function Main()

   ? RGBToHex( 255, 69, 0 )

return nil

function RGBToHex( nRed, nGreen, nBlue )

return "#" + PadL( hb_NumToHex( nRed ), 2, "0" ) + ;
             PadL( hb_NumToHex( nGreen ), 2, "0" ) + ;
             PadL( hb_NumToHex( nBlue ), 2, "0" )
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 1392
Joined: Mon May 14, 2007 09:49 AM

Re: Color format

Posted: Tue Jun 24, 2025 06:16 AM

Thanks, I got it !

RGB( 255, 69, 0 ) returns the number 17919. Is it possible to convert this number 17919 to #FF4500 ?

Or get the values Red, Green, Blue from 17919 ?

Posts: 99
Joined: Thu Jul 12, 2007 02:02 PM

Re: Color format

Posted: Tue Jun 24, 2025 02:40 PM
Hi Natter,

try this
FUNCTION NumToColor( nNum )
        LOCAL   cBuf
        
        cBuf := PadL( hb_NumToHex( nAnd( nNum, 255 ) ), 2, "0" )        
        nNum := INT( nNum / 256 )        
        cBuf += PadL( hb_NumToHex( nAnd( nNum, 255 ) ), 2, "0" )        
        nNum := INT( nNum / 256 )        
        cBuf += PadL( hb_NumToHex( nAnd( nNum, 255 ) ), 2, "0" )
RETURN "#" + cBuf
Posts: 1392
Joined: Mon May 14, 2007 09:49 AM

Re: Color format

Posted: Tue Jun 24, 2025 03:56 PM
Hi MaxP,

I did this. Everything is working well
'#'+numtohex(nRGBRed(num),2)+numtohex(nRGBGreen(num),2)+numtohex(nRGBBlue(num),2)

Continue the discussion