// 将rgb颜色转成hex , 列如 输入(24,12,255)
export function colorRGB2Hex(r, g, b) {
let hex = "#" + ((1 << 24) + (r << 16) + (g << 8) + b).toString(16).slice(1);
return hex;
}
//返回结果:#180cff
// 将hex颜色转成rgb, 输入(“#3ba272”)
// 将hex颜色转成rgb
export function hexToRgba(hex, opacity) {//hex:"#3ba272"; opacity:透明度
let RGBA = "rgba(" + parseInt("0x" + hex.slice(1, 3)) + "," + parseInt("0x" + hex.slice(3, 5)) + "," + parseInt(
"0x" + hex.slice(5, 7)) + "," + opacity + ")";
return {//返回值对象
red: parseInt("0x" + hex.slice(1, 3)),
green: parseInt("0x" + hex.slice(3, 5)),
blue: parseInt("0x" + hex.slice(5, 7)),
rgba: RGBA
};
//返回结果:{blue: 114, green: 162 ,red: 59 ,rgba: "rgba(59,162,114,1)"}
}