【发布时间】:2020-08-29 16:34:00
【问题描述】:
我正在使用图像选择器插件来获取图像表单库。因此,如果用户先拍照,然后使用图库获取图片,则可以正常工作。
但是,如果用户在没有(使用相机)的情况下选择直接图库,那么应用会崩溃而不会出现任何错误。
//Get options on device if camera or gallery
presentActionSheet() {
let actionSheet = this.actionSheetCtrl.create({
title: 'Choose or take a picture',
buttons: [
{
text: 'Take a picture',
handler: () => {
this.takePicture();
}
},
{
text: 'Choose pictures',
handler: () => {
this.openImagePicker();
}
}
]
});
actionSheet.present();
}
图像选择器的功能在这里。
//Open image picker multiple images
openImagePicker(){
this.pic = 'undefined';
let options = {
maximumImagesCount: 1,
}
//initalize readAsArrayBuffer for base64 and images gallery to display on view
this.photos = new Array<string>();
this.base64Data = new Array<string>();
this.imagePicker.getPictures(options)
.then((results) => {
this.reduceImages(results).then(() => {
console.log('all images cropped!!');
for (let index = 0; index < results.length; index++) {
//here iam converting image data to base64 data and push a data to array value.
console.log('Seelcted images are');
//console.log(this.imageSelected);
this.base64.encodeFile(results[index]).then((base64File: string) => {
//Create a base64 array for server transfer
this.base64Data.push(base64File);
}, (err) => {
console.log(err);
});
}
//console.log("Image Lists", this.photos);
});
}, (err) => { console.log(err) });
}
我正在使用的插头
import { Camera } from '@ionic-native/camera';
import { ImagePicker } from '@ionic-native/image-picker';
import { Crop } from '@ionic-native/crop';
import { FileTransfer, FileUploadOptions, FileTransferObject } from '@ionic-native/file-
transfer';
import { FilePath } from '@ionic-native/file-path';
import { File } from '@ionic-native/file';
import { Base64 } from '@ionic-native/base64';
这有什么问题?我正在使用 ionic3
【问题讨论】:
-
您可以授予使用画廊的权限吗?
标签: ionic3