可以通过设置Image组件的colorFilter值达到更改图片颜色的效果。参考此链接:https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/ts-basic-components-image-V5\#colorfilter9@Entry @Component struct Index { @State color: number[] = [0.78, 0, 0, 0, 0, 0, 0.93, 0, 0, 0, 0, 0, 0.80, 0, 0, 0, 0, 0, 1, 0] build() { Row() { Column() { Image($r("app.media.white")) .width("50%") .colorFilter(this.color) Button("切换").onClick(() => { // #FAF9DE this.color = [0.98, 0, 0, 0, 0, 0, 0.976, 0, 0, 0, 0, 0, 0.817, 0, 0, 0, 0, 0, 1, 0] }) } .width('100%') } .height('100%') } }
可以通过设置Image组件的colorFilter值达到更改图片颜色的效果。
参考此链接:https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/ts-basic-components-image-V5\#colorfilter9