HarmonyOS 鸿蒙Next 中 plugin 获取flutter图片资源问题
HarmonyOS 鸿蒙Next 中 plugin 获取flutter图片资源问题
关于HarmonyOS 鸿蒙Next 中 plugin 获取flutter图片资源问题的问题,您也可以访问:https://www.itying.com/category-93-b0.html 联系官网客服。
binding.getFlutterAssets().getAssetFilePathByName('xxxx')得到的只是资源路径,
加载原生图片资源可以试试下面的代码:
[@State](/user/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())
}
}
}
<button style="position: absolute; padding: 4px 8px 0px; cursor: pointer; top: 8px; right: 8px; font-size: 14px;">复制</button>
let rawfile = await rmg.getRawFileContent(“flutter_assets/”+this.image );
这行代码为耗时操作,debug时会暂不执行当前方法的剩余代码直到耗时操作返回结果,而进入build只是正常渲染流程
可以了,感谢