我正在尝试使用ImagePicker插件在离子应用程序中选择多张图像,但是当我仅选择一张图像时,但是如果我选择了更多图像,则该应用程序将关闭
版本
ionic:4.0.3
android:7.0.0
imagePicker:2.2.2
代码
getPermission() {
this.imagePicker.hasReadPermission()
.then(res => {
if (res) {
this.openGallery()
} else {
this.imagePicker.requestReadPermission()
.then(res => {
if (res === 'ok') {
this.openGallery()
}
})
}
})
.catch(error => console.log(error))
}
openGallery(){
let options = {
maximumImagesCount: 10,
width: 500,
height: 500,
quality: 100,
outputType: 1
}
this.imagePicker.getPictures(options)
.then(file => {
this.images = new Array(file.length);
for (let i = 0; i < file.length; i++) {
this.images[i] = 'data:image/jpeg;base64,' + file[i]
}
})
}
有什么解决方法的帮助吗?
答案 0 :(得分:1)
constructor(public navCtrl: NavController,
private camera: Camera,
private transfer: FileTransfer,
private file: File,
private fileOpener: FileOpener,
private loadingCtrl: LoadingController,
private plt: Platform,
private imagePicker: ImagePicker,
private base64: Base64,
private sanitizer: DomSanitizer) {
}
images=[];
public items: Array<{ images: string;}> = [];
takePhoto(){
this.imagePicker.hasReadPermission()
.then(res => {
if (res) {
this.openGallery();
} else {
this.imagePicker.requestReadPermission()
.then(res => {
if (res === 'ok') {
this.openGallery();
}
})
}
})
.catch(error => console.log(error));
}
openGallery () {
let options = {
maximumImagesCount: 10,
correctOrientation: true,
quality: 30,
width: 100,
height: 100,
allowEdit : true,
outputType: 1,
}
this.imagePicker.getPictures(options)
.then(file => {
//this.images = new Array(file.length);
for (let i = 0; i < file.length; i++) {
//this.images[i] = 'data:image/jpeg;base64,' + file[i]
this.images.push('data:image/jpeg;base64,' +file[i]);
}
});
}
我一直在寻找与您一样的解决方案……您的代码很完美……请参见通过添加“;”进行的细微更改。并减小图像尺寸和质量... 恭喜,感谢您对我的帮助!在手机上查看是否使用了杀死所有APP的方法,因为这也可能是导致您访问相机时应用停止的原因,因为它死了...。