我使用原生插件http://ionicframework.com/docs/native/camera/访问相机或照片库。 如有必要,我需要一个解决方案来访问相机并切换到相片库。 是否有这样的插件?
答案 0 :(得分:2)
正如Swapnil Patwa在评论中所说,你可以向用户提出一个ActionSheet:
public showActionSheet() {
let actionSheet = this.actionSheetCtrl.create({
buttons: [{
text: 'Load from gallery',
handler: () => {this.loadImage(this.camera.PictureSourceType.PHOTOLIBRARY);}
},{
text: 'Take a photo',
handler: () => {this.loadImage(this.camera.PictureSourceType.CAMERA);}
},{
text: 'Cancel',
role: 'cancel'
}]
});
actionSheet.present();
}
private loadImage(selectedSourceType:number){
let cameraOptions: CameraOptions = {
sourceType: selectedSourceType,
destinationType: this.camera.DestinationType.DATA_URL,
quality: 100,
encodingType: this.camera.EncodingType.JPEG,
mediaType: this.camera.MediaType.PICTURE,
correctOrientation: true,
}
this.camera.getPicture(cameraOptions).then((imageData) => {
if(imageData!=null){
// Do with the image data what you want.
}
});
}