This answer解释了像4280362283这样的数字是原始的十进制颜色代码。我正在使用的图书馆通过这些。转换它们的算法是什么?我已经在墙上进行了一些这样的尝试,但到目前为止还没有任何卡住:
console.log("Dec:", arr1[0])
let num1 = parseInt(arr1[0], 16);
console.log("Hex:", num1);
let r = parseInt(num1.toString().slice(0, 3), 16);
let g = parseInt(num1.toString().slice(3, 6), 16);
let b = parseInt(num1.toString().slice(6, 9), 16);
console.log("r, g, b:", r, g, b);
答案 0 :(得分:2)
4280362283看起来像是Android的ARGB颜色(请参见下面来自Kaiido的评论)。以下功能来自此post
function ARGBtoRGBA(num) {
num >>>= 0;
let b = num & 0xFF,
g = (num & 0xFF00) >>> 8,
r = (num & 0xFF0000) >>> 16,
a = ( (num & 0xFF000000) >>> 24 ) / 255 ;
return "rgba(" + [r, g, b, a].join(",") + ")";
}
let x = ARGBtoRGBA(4280362283);
console.log(x);