【发布时间】:2019-04-04 18:10:54
【问题描述】:
我使用 Ionic4 开发了一个 android 应用程序。我在使用 Ionic Native Camera 插件时遇到了一些问题。以下是我的代码。我面临的问题如下。如果我使用的相机插件版本是"@ionic-native/camera": "^5.3.0",。
问题
- 图库未打开
- 捕获的图像未返回。
- 拍照后应用程序崩溃
html
<img [src]="studentImage!==null ? studentImage: 'assets/icon/ic_avatar.png'" class="add-picture" (click)="addImage()">
.ts
public addImage() {
this.genericServices.presentActionSheet(this.openGallery, this.openCamera);
}
private openCamera = () => {
this.studentImage = this.genericServices.selectPicture('camera');
console.log('Captured Image:=>' + this.studentImage);
}
private openGallery() {
this.studentImage = this.genericServices.selectPicture('gallery');
}
服务
public async selectPicture(source) {
let base64Image = null;
const cameraOptions: CameraOptions = {
quality: 75,
destinationType: this.camera.DestinationType.DATA_URL,
encodingType: this.camera.EncodingType.PNG,
mediaType: this.camera.MediaType.PICTURE,
sourceType: source === 'camera' ? this.camera.PictureSourceType.CAMERA : this.camera.PictureSourceType.PHOTOLIBRARY,
correctOrientation: true
};
await this.camera.getPicture(cameraOptions).then((imageData) => {
console.log('Returned Image=>' + base64Image);
return base64Image = 'data:image/jpeg;base64,' + imageData;
}).catch(() => {
});
}
【问题讨论】:
标签: android cordova cordova-plugins ionic4 ionic-native