改变图片的颜色
/** * 将十六进制颜色(如:0xFFFFFF)转化为RGB格式颜色 */ public hexColorToRGB(hexColor) { let r = Math.floor(hexColor / 0x10000) % 0x100 let g = Math.floor(hexColor / 0x100) % 0x100 let b = Math.floor(hexColor / 0x1) % 0x100 return [r, g, b] } /** * 将十六进制颜色(如:0xFFFFFF)转化为颜色矩阵 */ public hexColorToMatrix(color) { let rgb = this.hexColorToRGB(color) let colorMatrix = [ 0, 0, 0, 0, rgb[0], 0, 0, 0, 0, rgb[1], 0, 0, 0, 0, rgb[2], 0, 0, 0, 1, 0 ]; return colorMatrix }
//图片写入颜色 img.filters = new egret.ColorMatrixFilter(this.hexColorToMatrix(0x8c4fb6))