Egret没有直接给image提供修改颜色属性,但是我们可以使用滤镜来修改image的颜色。
下面是我使用的核心代码,粘贴出来,可以直接使用
public setImageColor(image: eui.Image, color: number) { // 将16进制颜色分割成rgb值 let spliceColor = (color) => { let result = {r: -1, g: -1, b: -1}; result.b = color % 256; result.g = Math.floor((color / 256)) % 256; result.r = Math.floor((color / 256) / 256); return result; } let result = spliceColor(color); let colorMatrix = [ 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0 ]; colorMatrix[0] = result.r; colorMatrix[6] = result.g; colorMatrix[12] = result.b; let colorFilter = new egret.ColorMatrixFilter(colorMatrix); image.filters = [colorFilter]; }
关于滤镜的使用可以查看官网:http://developer.egret.com/cn/github/egret-docs/Engine2D/filter/filter/index.html
文章来源: Egret -- 更改Image颜色