HarmonyOS Image组件想给png设置颜色,文档让用colorFilter,但是没有示例说明4x5rgba矩阵

HarmonyOS Image组件想给png设置颜色,文档让用colorFilter,但是没有示例说明4x5rgba矩阵。

HarmonyOS
2024-10-10 13:09:09
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
FengTianYa

示例如下:

import drawing from '@ohos.graphics.drawing';  
import common2D from '@ohos.graphics.common2D';  
@Entry  
@Component  
struct ImageExample {  
  @State imageSrc: string = "https:\/\/img.ljcdn.com\/beike\/bk\/1645430577971.png";  
  translateColor(colorStr: string): common2D.Color {  
    let alpha0: number = parseInt(colorStr[1] + colorStr[2], 16);  
    let red0: number = parseInt(colorStr[3] + colorStr[4], 16);  
    let green0: number = parseInt(colorStr[5] + colorStr[6], 16);  
    let blue0: number = parseInt(colorStr[7] + colorStr[8], 16);  
    let color: common2D.Color = {  
      alpha: alpha0,  
      red: red0,  
      green: green0,  
      blue: blue0  
    }  
    return color;  
  }  
  @State DrawingColorFilter: ColorFilter | undefined =  
    drawing.ColorFilter.createBlendModeColorFilter(this.translateColor('#FF1A66FF'), drawing.BlendMode.SRC_ATOP);  
  build() {  
    Column() {  
      Image(this.imageSrc)  
        .width(100)  
        .height(100)  
      Image(this.imageSrc)  
        .width(100)  
        .height(100)  
        .colorFilter(this.DrawingColorFilter)  
    }  
  }  
}
  • 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.
  • 32.
  • 33.

getColorSync(r.id).toString(ResourceUtils.HEX_NUMBER) resourceManager里面的这个方法,返回的int直接转16进制。参考文档:https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/js-apis-resource-manager-V5#resource9

分享
微博
QQ
微信
回复
2024-10-10 15:52:25
相关问题
没有canvas设置ColorFilter的方法?
1216浏览 • 1回复 待解决
HarmonyOS Image组件如何设置填充颜色
938浏览 • 1回复 待解决
HarmonyOS 如何image设置遮罩 ?
1106浏览 • 1回复 待解决
怎么修改PNG图片的颜色
1616浏览 • 1回复 待解决
HarmonyOS 支持gif设置颜色
883浏览 • 1回复 待解决
使用colorFilter修改图片颜色
1195浏览 • 1回复 待解决
png图片使用Image组件加载出现锯齿
2544浏览 • 1回复 待解决
TextField怎么某段文字设置颜色
9674浏览 • 2回复 待解决
HarmonyOS 如何设置图片的colorfilter
1007浏览 • 1回复 待解决