
Security News
How Enterprise Security Is Adapting to AI-Accelerated Threats
Socket CTO Ahmad Nassri discusses why supply chain attacks now target developer machines and what AI means for the future of enterprise security.
cordova-plugin-imagepicker-tf
Advanced tools
非常感谢南尘和 banchichen 提供的源码支持 多点star✨开源不容易,谢谢。扣扣群:273613165
一个支持多选,相册实现了拍照、预览、图片压缩等功能
cordova plugin add https://github.com/giantss/cordova-plugin-ImagePicker.git注意:Android 项目先不要直接 build ,见 android注意事项。
| Android | iOS |
|---|---|
![]() | ![]() |
// 选图
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 及以下版本(对应Cordova-Android@6.3.0及以下版本),请将 cordova-plugin-ImagePicker\src\android\imagepicker.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 }FAQs
Cordova ImagePicker Plugin
We found that cordova-plugin-imagepicker-tf demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Socket CTO Ahmad Nassri discusses why supply chain attacks now target developer machines and what AI means for the future of enterprise security.

Security News
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.

Security News
Experts push back on new claims about AI-driven ransomware, warning that hype and sponsored research are distorting how the threat is understood.