Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Converting from Web color to RGB
Message
De
28/07/2001 09:58:51
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
 
À
27/07/2001 18:56:06
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00536716
Message ID:
00536837
Vues:
8
This message has been marked as the solution to the initial question of the thread.
>>>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
>
>I probobably didn't explain well what I needed.
>
>The following code solves my situation:
>
>
>PARAMETER lcWebColor
>set library to foxtools additive
>lnVFPColor=evaluate("0x" + substr(lcWebColor,5,2) + substr(lcWebColor,3,2) + substr(lcWebColor,1,2))
>RGBComp( lnVFPColor, @lnRed, @lnGreen, @lnBlue )
>
Michel,
lnRed=eval('0x'+substr(lcWebColor,1,2))
lnGreen=eval('0x'+substr(lcWebColor,3,2))
lnBlue=eval('0x'+substr(lcWebColor,5,2))
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform