Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Converting from Web color to RGB
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00536716
Message ID:
00536740
Vues:
9
>From this Web color, "B49C92", how can I find its RGB equivalent?

The RGB is a multiplication of the 3 colors, so you have to convert the hex to decimal, them multiply the three together.

I found this function to do the hex to decimal conversion:
FUNCTION dec
PARAMETERS l1hex
PRIVATE l1loop,l1int,l1str,l1ctr
l1str='0123456789ABCDEF'
l1int=0
FOR l1loop=LEN(l1hex)-1 TO 0 STEP -1
    l1int=l1int+(16^l1loop)*(AT(SUBSTR(l1hex,LEN(l1hex)-l1loop,1),l1str)-1)
ENDFOR
RETURN l1int
It looks the the function is 0 based and the RGB is 1 based, so to do the conversion you would have to do this:
?(dec("B4")+1)*(dec("9C")+1)*(dec("92")+1)

I still may be off by one because
? getcolor() ' select white
returns 16777215

?(dec("FF")+1)*(dec("FF")+1)*(dec("FF")+1)
returns 16777216

? getcolor() ' select black
returns 0
?(dec("00+1)*(dec("00")+1)*(dec("00")+1)
returns 1

so subtract 1 from the result and that should give you the correct result
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform