如何在Ionic 4中的iPhone上显示base64图像 [英] How to display base64 image on iPhone in Ionic 4

查看:238
本文介绍了如何在Ionic 4中的iPhone上显示base64图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用电容器插件来获取图像文件(从相机或画廊). PC和Android可以正常工作,但是代码在iPhone上崩溃.

I am using Capacitor Plugins to get the image file (from camera or gallery). PC and Android are working fine, but the code crashes on iPhone.

它打开图库,我抓住图像,尝试显示时崩溃

It opens the galery, I grab the image and it crashes when trying to display

我检查了权限,它们都已设置. 为什么只在ios上崩溃?字符串有问题吗?安全吗?

I checked the permissions and they are all set. Why would it crash only on ios? Is it a problem with the string? Security?

HTML:

< ion-img role="button" class="image" [src]="selectedImage" *ngIf="selectedImage" >

TS代码:

Plugins.Camera.getPhoto({
    quality: 100,
    source: CameraSource.Prompt,
    correctOrientation: true,
    allowEditing: false,
    resultType: CameraResultType.Base64
})
 .then(image => {
      this.selectedImage = image.base64Data; // VAR TO DISPLAY IN HTML
  })

错误日志 https://i.imgur.com/jrSgGeW.jpg

现在,我使用DomSanitizer和SafeResourceUrl进行变量设置.错误停止了,但是图像仍然无法显示

Now Im using DomSanitizer and SafeResourceUrl to variable. The error stopped, but the image wont display though

推荐答案

更改此行

this.selectedImage = "data:image/jpeg;base64, " + image.base64Data;

这篇关于如何在Ionic 4中的iPhone上显示base64图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆