首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >拍完照片后又打电话给摄像头?

拍完照片后又打电话给摄像头?
EN

Stack Overflow用户
提问于 2018-04-30 15:40:37
回答 1查看 125关注 0票数 1

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

代码语言:javascript
复制
startCamera() {
  if(this.pictureList.length >= 4) {
    this.alertController.create({
      title: this.singleton.TITLE_ERROR,
      message: this.singleton.MESSAGE_TOOMANYPHOTOS,
      buttons: [
        {
          text: 'Ok',
        }
      ]
    }).present();
    return;
  }

  let imageData = "";
  this.camera.getPicture(this.options).then((imageData) => {
    this.pictureList.push(imageData);

    let temp = [];
    for (let i of this.pictureList) i && temp.push(i);

    this.pictureList = temp;
    this.slides.refresh();
  }, (err) => {
    console.log(err);
  });
}

但是,相机不重新启动进入相机吗?有什么理由不能这样做吗?我在想是因为我试图在承诺中调用一个函数吗?

谢谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-04-30 16:25:36

也许使用递归您可以这样做,我留给您一个未经验证的示例,但这在逻辑上可以为您服务:

我是基于一个将其保存在Base 64中的应用程序来执行这个示例的,但是根据您的需要将推送应用到列表中。

代码语言:javascript
复制
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);
      }
    );
  }
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50103840

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档