ionic3 - 从图库中选择图像时 Ionic3 应用程序崩溃
问题描述
我正在使用图像选择器插件来获取图像表单库。因此,如果用户先拍照,然后使用图库获取图片,则它可以正常工作。
但是,如果用户在没有(使用相机)的情况下选择直接图库,则应用程序崩溃而没有任何错误。
//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';
这有什么问题?我正在使用离子3
解决方案
我也遇到了这个问题,似乎有些内存泄漏。
然后我尝试了 Cordova 插件的分叉版本,它工作正常。
https://github.com/abelabbesnabi/cordova-plugin-image-picker
推荐阅读
- reactjs - 这种在 React 中构建基本用户身份验证的方法是否正确?
- c# - PInvoke 本机共享库中的宏
- python - 如何在 Heroku 中修复错误的 Procfile
- javascript - 每个附加孩子的不同ID?
- excel - 需要使用 Excel vba 合并两个 xml 文件
- r - 如何在R中执行多列的countifs()函数(计算文本值)
- c++ - C ++如何动态保存大量数组?
- android - 如何使用多个磨损操作系统布局并以编程方式交换它们
- python - “扁平化”列表包含列表列表到列表列表
- python - 如何在 Python 中使用类(类在我的代码中不起作用)