目前,我正在开发一款应用程序,需要至少拍摄4张照片。每次拍照时,我都会重新启动相机,这样他们就不用再点击应用菜单上的“拍照”按钮了。到目前为止,我的代码如下:
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);
});
}但是,相机不重新启动进入相机吗?有什么理由不能这样做吗?我在想是因为我试图在承诺中调用一个函数吗?
谢谢
发布于 2018-04-30 16:25:36
也许使用递归您可以这样做,我留给您一个未经验证的示例,但这在逻辑上可以为您服务:
我是基于一个将其保存在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);
}
);
}https://stackoverflow.com/questions/50103840
复制相似问题