我正在使用ionic2和angular2来开发移动应用。
在页面中,用户必须从图库/相机加载图像。
从相机加载图像工作正常。但是从图库加载图片不起作用。它也会导致相机。
this.camera.PictureSourceType.PHOTOLIBRARY 也会导致相机。
我的代码如下:
-s
请帮帮我。提前致谢
此外,Android中的麦克风工作正常没有任何问题。但是对于ios来说,麦克风并没有预期的工作。我有什么改变吗?
import { Camera, CameraOptions } from '@ionic-native/camera';
import { SpeechRecognition } from '@ionic-native/speech-recognition';
..
..
..
takePicture(type) {
this.showActionSheet(type);
}
public showActionSheet(type) {
let actionSheet = this.actionSheetCtrl.create({
title: 'Choose the source type',
buttons: [{
icon: 'camera',
text: 'Camera',
handler: () => {
this.loadImage(this.camera.PictureSourceType.CAMERA, type);
}
}, {
icon: 'image',
text: 'Gallery',
handler: () => {
this.loadImage(this.camera.PictureSourceType.PHOTOLIBRARY, type);
}
}, {
text: 'Cancel',
role: 'cancel'
}]
});
actionSheet.present();
}
private loadImage(selectedSourceType: number, type) {
let cameraOptions: CameraOptions = {
sourceType: selectedSourceType,
destinationType: this.camera.DestinationType.FILE_URI,
quality: 100,
allowEdit : true,
encodingType: this.camera.EncodingType.JPEG,
mediaType: this.camera.MediaType.PICTURE,
correctOrientation: true,
}
this.camera.getPicture({
destinationType: this.camera.DestinationType.DATA_URL,
}).then((imageData) => {
if (type === 'single') {
this.base64Image = "data:image/jpeg;base64," + imageData;
} else {
this.image = "data:image/jpeg;base64," + imageData;
this.imageList.push(this.image);
}
}, (err) => {
console.log(err);
});
}