以下函数转换一个十进制数字,该数字表示一种以Microsoft Windows存储颜色的方式存储的颜色(低字节为红色),并将其转换为Web应用程序所需的十六进制字符串,即“ #RRGGBB”。
function decimalColorToHTMLcolor(number) {
//converts to a integer
var intnumber = number - 0;
// isolate the colors - really not necessary
var red, green, blue;
// needed since toString does not zero fill on left
var template = "#000000";
// in the MS Windows world RGB colors
// are 0xBBGGRR because of the way Intel chips store bytes
red = (intnumber&0x0000ff) << 16;
green = intnumber&0x00ff00;
blue = (intnumber&0xff0000) >>> 16;
// mask out each color and reverse the order
intnumber = red|green|blue;
// toString converts a number to a hexstring
var HTMLcolor = intnumber.toString(16);
//template adds # for standard HTML #RRGGBB
HTMLcolor = template.substring(0,7 - HTMLcolor.length) + HTMLcolor;
return HTMLcolor;
}