首页 话题 小组 问答 好文 用户 我的社区 域名交易

[分享]harmonyos 中plugin 获取flutter图片资源问题?

发布于 2024-08-24 18:46:52
0
294


binding.getFlutterAssets().getAssetFilePathByName('xxxx')得到的是资源路径,加载原生图片资源可以参考如下代码:
@State imageSource:image.ImageSource|null=null

async aboutToAppear()
{
let args: HashMap<string, object | string> = this.viewManager.args as HashMap<string, object>
this.image = args.get('src') as string
let rmg = DemoPluginAssetPlugin.binding.getApplicationContext().resourceManager;
let rawfile = await rmg.getRawFileContent("flutter_assets/"+this.image );
let buffer = rawfile.buffer.slice(0);
this.imageSource = image.createImageSource(buffer);
}

build() {
Column(){
if(this.imageSource){
Image(this.imageSource.createPixelMapSync())
}
}
}
评论
天启
Lv.1普通用户

258

帖子

20

小组

475

积分

站长交流