image - 显示 ERR_INVALID_URL 的离子图片
问题描述
嗨 ionic,我正在尝试显示图片,但出现 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
解决方案
使用文件插件如下。
this.file.readAsDataURL(path, fileName).then(imageBase64 => {
this.picture = imageBase64;
});
<img src="{{picture}}">
推荐阅读
- c - 有符号整数和无符号整数
- image - R:将绘图从绘图窗口强制转换为光栅对象
- python - 如何在没有 Onehot 编码的情况下将行数据转换为列
- swagger - Swagger/OpenApi Codegen 从 xsd 生成请求正文
- javascript - 当存在多个选择框时,jquery select2选项冲突
- python - Pandas,在 groupby 调用中重命名重复列
- swift - 覆盖的方法快速调用扩展(类别)中声明的原始方法?
- python - 返回所有单词的正则表达式,星号之间的任何文本除外
- sql - 根据轮班时间计算总停机时间
- android - 我制作了一个嵌入网站的应用程序。如何使其中的任何视频能够处于全屏模式?