【问题标题】:Error displaying image using Capacitor and Ionic使用电容器和离子显示图像时出错
【发布时间】:2019-10-20 14:03:42
【问题描述】:

我正在尝试使用 Ionic 4 编写一个简单的相机应用程序,这是我的代码 sn-p,用于捕获图像并将其显示在 Ionic 选项卡中。

export class UploadPage {
  yourImage: SafeResourceUrl;

  constructor(private sanitizer: DomSanitizer) {  }

  async captureImage() {
    const capturedImage = await Plugins.Camera.getPhoto(
    {
      quality: 90,
      allowEditing: true,
      source: CameraSource.Camera,
      resultType: CameraResultType.Uri
    });

    this.yourImage = this.sanitizer.bypassSecurityTrustResourceUrl(capturedImage && (capturedImage.dataUrl));

    }
  }

当我尝试运行代码时,它看起来可以捕获图像,但它没有显示在浏览器中。我看到了这个

在网络控制台中,我看到了这个

该图像也不会显示在 devapp 中。

奇怪的是,当我在 Android 手机上测试时,图像在磁盘上保存得很好,但它仍然没有显示在页面上。

【问题讨论】:

    标签: angular ionic-framework ionic4 capacitor


    【解决方案1】:

    如果你使用 resultType Uri,你必须使用 captureImage.webPath 来显示 url,除非你使用 resultType DataUrl,否则 dataUrl 是未定义的

    【讨论】:

    • 感谢您的回答。这是不相关的,但我无法让整个相机 + 显示使用电容器在 devapp 中工作的图片。你知道我怎样才能让它工作吗?
    • Devapp 不适用于电容器应用程序,它仅适用于 cordova 应用程序
    猜你喜欢
    • 2022-11-12
    • 2016-07-11
    • 2021-12-06
    • 2019-12-15
    • 1970-01-01
    • 1970-01-01
    • 2020-10-18
    • 2017-08-13
    • 2021-07-19
    相关资源
    最近更新 更多