当给Image组件传入沙箱路径中的图片时,图片不显示,在日志中可以看到一系列错误:
GetAsset failed: data/storage/el2/base/haps/entry/cache/crop_1752232915324.jpg
No asset data! NodeId = 269-243.
Fail load imageData. src = <private>, nodeId = 269-243.
Image LoadFail
根本原因:
Image组件不能直接传入应用沙箱路径,需要传入应用沙箱uri;
解决方案:拿到文件的沙箱路径后,通过调用@ohos.file.fileuri模块的fileuri.getUriFromPath(file.path)将沙箱路径转化为沙箱uri,传入之后即可正常显示。this.ImageUri = fileUri.getUriFromPath(ImagePath);