Ionic framework 照相机和照片库在一起Ionic 2
我使用本机插件访问相机或照片库。 我需要一个解决方案来访问相机,并在必要时切换到照片库。Ionic framework 照相机和照片库在一起Ionic 2,ionic-framework,ionic2,ionic-native,Ionic Framework,Ionic2,Ionic Native,我使用本机插件访问相机或照片库。 我需要一个解决方案来访问相机,并在必要时切换到照片库。 是否有这样的插件?正如Swapnil Patwa在评论中所说,您可以向用户询问操作表: public showActionSheet() { let actionSheet = this.actionSheetCtrl.create({ buttons: [{ text: 'Load from gallery', handler: () => {th
是否有这样的插件?正如Swapnil Patwa在评论中所说,您可以向用户询问操作表:
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.
}
});
}
正如Swapnil Patwa在评论中所说的,您可以向用户询问操作表:
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.
}
});
}
您可以提示用户选择gallery或camera。但您无法切换。您可以提示用户选择gallery或camera。但是你不能切换。现在我使用actionSheet,但是,例如,在
Viber
应用程序中,你可以选择一个摄像头并切换到照片库。我想这样组织。Camera是一个原生插件,我认为它不允许你这么做,在Ionic 2的文档中我找不到这个选项。现在我使用actionSheet,但是,例如,在Viber
应用程序中,你可以选择一个摄像头并切换到照片库。我想这样组织。相机是一个原生插件,我不认为它允许你这样做,在爱奥尼亚2的文档中我找不到这个选项。