我正在尝试显示照片库中的图像。它返回我,file:///storage/emulated/0/Android/data/com.xxx.mobile/cache/20200306_121224.jpgHTML标签img不会呈现此路径。
。ts文件
const cameraOptions = {
sourceType: this.camera.PictureSourceType.PHOTOLIBRARY,
destinationType: this.camera.DestinationType.FILE_URI,
encodingType: this.camera.EncodingType.JPEG,
correctOrientation: true
}
this.camera.getPicture(cameraOptions).then((imageData) => {
if(imageData){
this.filePath.resolveNativePath(imageData).then(filePath => {
resolve(filePath);
//filePath variable is 'file:///storage/emulated/0/Android/data/com.xxx.mobile/cache/20200306_121224.jpg'
}).catch(err => console.log(err));
}
}, (err) => {
var error = JSON.stringify(err)
reject(error);
})
。html文件
<img [src]="item.FileURI" />
替换
resolve(filePath);
with
resolve((<any>window).Ionic.WebView.convertFileSrc(filePath))
来源:https://forum.ionicframework.com/t/unable-to-display-image-using-file-uri/84977/25