cordova-plugin-sinoservices-telerik-imagepicker
v1.0.1
Published
Sinoservices developed plugin
Downloads
90
Readme
imagePicker插件,支持Android
参考cordova-plugin-telerik-imagepicker插件,进行修改。
一,安装插件
cordova plugin add cordova-plugin-sinoservices-telerik-imagepicker
npm install --save @ionic-native/image-picker
二,使用方法
import {ImagePicker} from "@ionic-native/image-picker/";
@Injectable()
export class NativeService {
constructor(private imagePicker: ImagePicker) {
}
/**
* 通过相册选择获取照片
* @param maxCount 选择图片最大值,默认1。
* @param destinationType 选择照片类型,默认1。照片base64字符串:0;照片路径:1。
*/
getPictureByAlbum(maxCount: number = 1, destinationType: number = 1): Observable<any> {
let that = this;
let options = Object.assign({
maximumImagesCount: maxCount,//选择图片的最大值
destinationType: destinationType,//期望返回的图片格式
width: Constants.IMAGE_SIZE,//缩放图像的宽度(像素)
height: Constants.IMAGE_SIZE,//缩放图像的高度(像素)
quality: Constants.QUALITY_SIZE//图像质量,范围为0 - 100
});
return Observable.create(observer => {
that.imagePicker.getPictures(options).then(files => {
console.log("imagePicker==获取图片");
if (destinationType === 0) {//url路径
observer.next(files);
} else {
let imgBase64s = [];//base64字符串数组
for (let fileUrl of files) {//根据图片绝对路径转化为base64字符串
that.convertImgToBase64(fileUrl).subscribe(base64 => {
imgBase64s.push(base64);
if (imgBase64s.length === files.length) {
observer.next(imgBase64s);
}
})
}
}
}).catch(err => {
if (err == 20) {
alert('没有权限,请在设置中开启权限');
return;
}
alert(err);
console.log('通过相册选择多图失败');
// alert('获取照片失败');
});
});
}
}