2017-07-25 78 views

回答

1

由於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. 
     } 
    }); 
    } 
+0

現在我使用actionSheet,但是,例如,在'Viber'應用程序中,您可以選擇一個攝像頭並切換到照片庫。我想組織這種方式。 – wstudiokiwi

+0

相機是本地插件,我不認爲它允許你這樣做,在Ionic 2的文檔中,我沒有找到該選項。 –