FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour hex color
Posts: 7317
Joined: Thu Oct 18, 2012 07:17 PM
hex color
Posted: Mon Feb 29, 2016 11:27 AM

Can I use a hex color sample 0xFFFF00
How I can converte it into rgb color ?

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
Posts: 8515
Joined: Tue Dec 20, 2005 07:36 PM
Re: hex color
Posted: Mon Feb 29, 2016 02:00 PM
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
Posts: 1516
Joined: Thu May 27, 2010 02:06 PM
Re: hex color
Posted: Mon Feb 29, 2016 02:15 PM
Code (fw): Select all Collapse
function cHex2aRgb( cHexColor )
local nR,nG,nB
local aRgb

   if  left(cHexColor,1) == "#"
      cHexColor := substr(cHexColor,2,len(cHexColor) )
   endif 

     if len(cHexColor) == 3
      nR = ft_Hex2Dec( substr(cHexColor,1,1))
      nG = ft_Hex2Dec( substr(cHexColor,2,1))
      nB = ft_Hex2Dec( substr(cHexColor,3,1))
   else
      nR = ft_Hex2Dec( substr(cHexColor,1,2))
      nG = ft_Hex2Dec( substr(cHexColor,3,2))
      nB = ft_Hex2Dec( substr(cHexColor,5,2))
   endif
   aRgb := {nR, nG, nB }

  return aRgb; // returns an array with the rgb values
Posts: 989
Joined: Thu Nov 24, 2005 03:01 PM
Re: hex color
Posted: Mon Feb 29, 2016 02:47 PM
Ciao Silvio,

Silvio.Falconi wrote:Can I use a hex color sample 0xFFFF00
How I can converte it into rgb color ?

Colors are longs with 3 components. Written in Hexadecimal the look like 0x<BB><GG><RR>, because longs are stores with less significan bytes first.
Have you tried to use it 'as is', changing the order? I mean

Code (fw): Select all Collapse
    DEFINE WINDOW oWnd FROM 0, 0 TO 100, 100 PIXEL TITLE "My color test" COLORS 0, 0x00FFFF
Saludos
Carlos Mora
http://harbouradvisor.blogspot.com/
StackOverflow http://stackoverflow.com/users/549761/carlos-mora
“If you think education is expensive, try ignorance"
Posts: 8515
Joined: Tue Dec 20, 2005 07:36 PM
Re: hex color
Posted: Mon Feb 29, 2016 03:13 PM
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341

Continue the discussion