>>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; >> } >>} >>