您好,我试图显示图片,但出现ERR_INVALID_URL错误。这是代码
resimekle()
{
const options: CameraOptions = {
quality: 100,
destinationType: this.camera.DestinationType.FILE_URI,
encodingType: this.camera.EncodingType.JPEG,
mediaType: this.camera.MediaType.PICTURE
}
this.camera.getPicture(options).then((imageData) => {
// imageData is either a base64 encoded string or a file URI
// If it's base64 (DATA_URL):
this.base64Image = 'data:image/jpeg;base64,' + imageData;
this.base64Image= this.base64Image.replace(/^file:\/\//, '');
}, (err) => {
// Handle error
});
}
<img [src]="_DomSanitizationService.bypassSecurityTrustUrl(base64Image)"/>
错误:data:image / jpeg; base64,file:///storage/emulated/0/Android/data/io.ionic.starter/cache/1542647016224.jpg net :: ERR_INVALID_URL
答案 0 :(得分:0)
按如下所示使用文件插件。
this.file.readAsDataURL(path, fileName).then(imageBase64 => {
this.picture = imageBase64;
});
<img src="{{picture}}">