Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Opposite of RGB?
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
01668191
Message ID:
01668226
Vues:
59
Dan,

Thanks a lot. I'm going to send this code to my colleague who is working on that form now.

BTW, that code is in a newer style of JavaScript, I think. I may need to learn this style.

>>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.
>
>Javeacript split into several functions in a color service:
>
>
>export class ColorService {
>
>  colorToHex(lncolor: number): string {
>    let rgb=this.colorToRGB(lncolor);
>    return this.RGBToHex(rgb[0],rgb[1],rgb[2]);
>  }
>
>  colorToRGB(lncolor: number ): number[] {
>    let b=Math.floor(lncolor/(256*256));
>    let g=Math.floor((lncolor-(b*256*256))/256);
>    let r=Math.floor(lncolor-b*256*256-g*256);
>    return [r,g,b];
>  }
>
>  RGBToHex(r,g,b): string {
>    let bin = r << 16 | g << 8 | b;
>    return '#'+(function(h){
>        return new Array(7-h.length).join("0")+h;
>    })(bin.toString(16).toUpperCase());
>  }
>
>  hexToColor(hex: string): number {
>    if (hex.length<6) {
>      let shorthandRegex = /^#?([a-f\d])([a-f\d])([a-f\d])$/i;
>      hex = hex.replace(shorthandRegex, function(m, r, g, b) {
>        return r + r + g + g + b + b;
>      });
>    }
>    let result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
>    let color=parseInt(result[1], 16)+parseInt(result[2], 16)*256+parseInt(result[3], 16)*256*256;
>    return color;
>  }
>}
>
If it's not broken, fix it until it is.


My Blog
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform