Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Opposite of RGB?
Message
De
22/04/2019 15:13:20
 
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
01668191
Message ID:
01668227
Vues:
58
>Hi everybody,
>
>We store result of the GetColor function in the database as integer value. Now we want to use this in Web Application to set the color. Do you know what is the simplest way to convert this integer value into the value suitable for HTML (in C# / JavaScript code, if possible)?
>
>Thanks in advance.

In VFP, the logic to break out the color components is in the function breakout_rgb(). After that, you re-assemble them into a hexadecimal equivalent.
LOCAL lnRgb, lnRed, lnGrn, lnBlu
lnRgb = RGB(255,192,128)
breakout_rgb(lnRgb, @lnRed, @lnGrn, @lnBlu)
lcColor = "#" + RIGHT(TRANSFORM(lnRed, "@0"), 2) + RIGHT(TRANSFORM(lnGrn, "@0"), 2) + RIGHT(TRANSFORM(lnBlu, "@0"), 2)
WAIT WINDOW lcColor

FUNCTION breakout_rgb
LPARAMETERS tnRgb, tnRed, tnGrn, tnBlu

    tnRed = BITAND(tnRgb, 0xff)
    tnGrn = BITAND(BITRSHIFT(tnRgb, 8), 0xff)
    tnBlu = BITAND(BITRSHIFT(tnRgb, 16), 0xff)
Logically it is this operation:
int lnRgb, lnRed, lnGrn, lnBlu;

lnRed = (lnRgb & 0xff);
lnGrn = ((lnRgb >> 8) & 0xff);
lnBlu = ((lnRgb >> 16) & 0xff);

// Right now, values are broken out
// I'm not sure in C# how to convert them to hex forms. In C, you could use this:
char color[32];
sprintf(color, "#%02x%02x%02x", lnRed, lnGrn, lnBlu);

Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform