离子 - 拍照后再次调用相机?

时间:2018-04-30 15:40:37

标签: angular ionic-framework ionic3

我正在开发一款需要至少拍摄4张照片的应用程序。我每次拍照都要重新启动相机,这样他们就不必再在应用菜单上再次点击拍照按钮了。到目前为止,这是我的代码:

 sh "docker run -d --name mongocontainer19" 
 sh "docker exec mongocontainer19 mongo mongodump"

然而,相机不会重新启动回相机?有什么理由不行吗?我想我试图在承诺中调用一个函数吗?

由于

1 个答案:

答案 0 :(得分:0)

也许使用递归你可以做到,我给你一个未经证实的例子,但这可以在逻辑上为你服务:

我根据将其保存在Base 64中的应用程序做了示例,但是根据需要在列表中应用了推送。

pictureList: any[];

  ngOnInit(): void {
    this.pictureList = null;
    this.optionsCamera = {
      quality: 50,
      destinationType: this._camera.DestinationType.DATA_URL,
      encodingType: this._camera.EncodingType.JPEG,
      mediaType: this._camera.MediaType.PICTURE,
      saveToPhotoAlbum: true
    };
    this.optionsGallery = {
      quality: 50,
      destinationType: this._camera.DestinationType.DATA_URL,
      sourceType: this._camera.PictureSourceType.PHOTOLIBRARY
    };
  }

  startCamera(): void {
    if (this.pictureList.length <= 4) {
      console.log('Open in length: ' + this.pictureList.length);
      this.getPhoto(this.optionsCamera);
      this.startCamera();
    }
  }

  getPhoto(options): void {
    this._camera.getPicture(options).then(
      imageData => {
        let base64Image = "data:image/jpeg;base64," + imageData;
        this.pictureList.push(base64Image);
      },
      err => {
        console.log("Could not open the camera: " + err);
      }
    );
  }