HarmonyOS 怎么给图片渲染不同的颜色

image($r(app.media.imageName))怎么给图片渲染不同的颜色?图片是png格式的,需求是展示出来的颜色根据客户端主题色改变。

HarmonyOS
2024-12-20 16:13:55
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
zxjiu

可以参考https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/ts-basic-components-image-V5#colorfilter9

具体demo如下:

import drawing from '@ohos.graphics.drawing';
import common2D from '@ohos.graphics.common2D';

@Entry
@Component
struct ImageExample {
  @State imageSrc: Resource = $r('app.media.icon');
  private color: common2D.Color = {
    alpha: 120,
    red: 34,
    green: 155,
    blue: 100
  };
  private color1: common2D.Color = {
    alpha: 190,
    red: 255,
    green: 30,
    blue: 0
  };
  @State DrawingColorFilter: ColorFilter | undefined =
    drawing.ColorFilter.createBlendModeColorFilter(this.color, drawing.BlendMode.MODULATE);
  @State DrawingColorFilter1: ColorFilter | undefined =
    drawing.ColorFilter.createBlendModeColorFilter(this.color1, drawing.BlendMode.MODULATE);

  build() {
    Column() {
      Image(this.imageSrc).width(100).height(100).colorFilter(this.DrawingColorFilter)
      Image(this.imageSrc).width(100).height(100).colorFilter(this.DrawingColorFilter1)
    }
  }
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
分享
微博
QQ
微信
回复
2024-12-20 18:11:58


相关问题
怎么修改PNG图片颜色
1629浏览 • 1回复 待解决
TextField怎么某段文字设置颜色
9674浏览 • 2回复 待解决
java鸿蒙Tab框架 image图片怎么渲染
7594浏览 • 2回复 待解决
HarmonyOS 支持gif设置颜色
889浏览 • 1回复 待解决
图片设置replaceholderImage方法
704浏览 • 1回复 待解决
HarmonyOS 图片颜色改变API
619浏览 • 1回复 待解决
HarmonyOS 顶部颜色怎么修改
686浏览 • 1回复 待解决
如何按钮添加图片
6603浏览 • 4回复 待解决
HarmonyOS 如何图片增加文字水印
703浏览 • 1回复 待解决
HarmonyOS 图片能否更改其颜色
1235浏览 • 1回复 待解决
如何获取图片颜色平均值
1707浏览 • 1回复 待解决
HarmonyOS 怎么修改richtext内文字颜色
662浏览 • 1回复 待解决
HarmonyOS Toggle空间颜色怎么修改?
1025浏览 • 1回复 待解决
使用colorFilter修改图片颜色
1195浏览 • 1回复 待解决