cordova plugin ImagePicker
修复 ios 13 选多张图可能会崩溃的问题
非常感谢南尘和 banchichen 提供的源码支持 多点star开源不容易,谢谢。扣扣群:273613165
一个支持多选,相册实现了拍照、预览、图片压缩等功能
cordova plugin add https://github.com/giantss/cordova-plugin-ImagePicker.git
注意:Android 项目先不要直接 build ,见 android注意事项。
Android | iOS |
---|---|
![]() |
![]() |
一个粗糙的 cordova demo
// 选图
ImagePicker.getPictures(function(result) {
alert(JSON.stringify(result));
}, function(err) {
alert(err);
}, {
maximumImagesCount : 9,
width : 1920,
height : 1440,
quality : 100
});
// 拍照
ImagePicker.takePhoto(function(result) {
alert(JSON.stringify(result));
}, function(err) {
alert(err);
}, {
width : 1920,
height : 1440,
quality : 50
});
返回结果如下:
// 如果是拍照,images 数组中只有一个对象
{
"images": [{
"path": "/data/user/0/com.pushsoft.im2/cache/ImagePicker/152783817455118.jpg",
"uri": "file:///data/user/0/com.pushsoft.im2/cache/ImagePicker/152783817455118.jpg",
"width": 720,
"height": 1280,
"size": 104871 // 文件体积(单位:字节)
}, {
"path": "/data/user/0/com.pushsoft.im2/cache/ImagePicker/152783817464525.jpg",
"uri": "file:///data/user/0/com.pushsoft.im2/cache/ImagePicker/152783817464525.jpg",
"width": 720,
"height": 1280,
"size": 109873
}],
"isOrigin": false // 是否原图
}
ionic 中使用本插件,需要声明: declare let ImagePicker:any
配置参数 | 参数含义 |
---|---|
maximumImagesCount | 多选限制数量,默认为9 |
width | 设置输出图片的width,默认为自动 |
height | 设置输出图片的height,默认为自动 |
quality | 图片质量 默认80 |
enablePickOriginal | 允许选择原图 默认true |
先移除安装过的旧版插件
如果 build 报下面的错
error: resource android:attr/dialogCornerRadius not found
error: resource android:attr/fontVariationSettings not found
error: resource android:attr/ttcIndex not found
请使用 cordova-android-support-gradle-release 这个插件统一项目中的 Android Support 库版本:
$ cordova plugin add cordova-android-support-gradle-release --variable ANDROID_SUPPORT_VERSION={required version}
其中{required version}
值为类似 26.+
,27.+
,28.+
这种。
如果你用的是 低版本 Cordova 和 Gradle,会报错不支持implementation
Cordova 7.1.0 及以下版本(对应[email protected]及以下版本),请将 cordova-plugin-ImagePickersrcandroidimagepicker.gradle
里面的 implementation
修改为 compile
,
因为低版本的 Cordova-Android 使用的是低版本的 Gradle, 不支持 implementation
。
如果还是 build 不成功
$ cordova platform rm android
或
$ cordova platform rm ios
移除旧的平台,然后重新 add
takePhoto
方法,直接进入拍照takePhoto
方法,直接进入拍照['xxx', 'yyy']
,现在是 { images: ['xxx', 'yyy'], isOrigin: true/false }
The MIT License (MIT)