Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Hex value
Message
 
To
01/08/1999 11:59:46
Senna Dwipayana
Indo Rebel Apparel Cv
Bandung, Indonesia
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Title:
Miscellaneous
Thread ID:
00248674
Message ID:
00248676
Views:
24
>Hi All,
>I need to convert hex color value to RGB Value, is there any code can do it ?
>
>TIA

Hi Senna,

You can convert the hexidecimal value directly, depending on what the source of the value is. For example, lndec = 0xFD, will assign the value 253 to lndec. If, however, you have the hex value as a string then lndec = EVALUATE('0x' + "FD"), will produce the same result.

Now, there are a couple of ways to retrieve the individual color values. Easiest, is to use the RGBComp() function in Foxtools. Another way is to use the bit functions to mask out the individual values. Here's how:
* Using RGBComp - Requires Foxtools
STORE 0 TO lnred, lngreen, lnblue
* lncolor is the color to break down
= RGBComp(lncolor, @lnred, @lngreen, @lnblue)
* Using the bit manipulation functions
lnblue = BITAND(lncolor, 255)
lncolor = BITRSHIFT(lncolor, 8)
lngreen = BITAND(lncolor, 255)
lncolor = BITRSHIFT(lncolor, 8)
lnred = BITAND(lncolor, 255)
Additionally, there are variations on the bit shifting above and also you could use integer division.

hth,
George

Ubi caritas et amor, deus ibi est
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform