【发布时间】:2019-12-18 19:20:57
【问题描述】:
我正在尝试使用camera Cordova plugin 显示从相机拍摄的图像或从应用内的设备中选取的图像。
使用this project as a guideline 我的代码:
安装插件:
$ ionic cordova plugin add cordova-plugin-camera
$ npm install --save @ionic-native/camera@4
在 html 文件中
<ion-header>
<ion-navbar>
<ion-title>Hello Ionic</ion-title>
</ion-navbar>
</ion-header>
<ion-content padding>
<h3 text-center>
{{imageSrc}}
</h3>
<div class="gallery-button" text-center>
<img [src]="imageSrc" />
</div>
</ion-content>
在 ts 文件中
import { Component } from '@angular/core';
import { Camera, CameraOptions } from '@ionic-native/camera';
.
.
.
.
private imageSrc: string;
getImage() {
let cameraOptions = {
sourceType: this.camera.PictureSourceType.PHOTOLIBRARY,
destinationType: this.camera.DestinationType.FILE_URI,
quality: 100,
targetWidth: 1000,
targetHeight: 1000,
encodingType: this.camera.EncodingType.JPEG,
correctOrientation: true
}
console.log(cameraOptions);
this.camera.getPicture(cameraOptions)
.then(file_uri => this.imageSrc = file_uri,
err => console.log(err));
}
}
问题是图像未显示在我的视图中,并在其位置出现损坏的图像图标,如下所示。我见过的所有示例都使用类似的代码,并且它们都存在图像链接损坏的问题,而不是显示的实际图像。
【问题讨论】:
-
您用作指南的那个项目是针对 Ionic4 的,它与您似乎试图定位的 Ionic3 完全不同。 (也不能很好地满足您的要求)
标签: cordova ionic-framework ionic2 ionic3 cordova-plugins