● 从本地相册选择图片或使用相机拍照chooseImage
分类:图片
是否支持H5:支持
参数
Object object
| 参数名 | 类型 | 默认值 | 必填 | 说明 |
|---|---|---|---|---|
| count | number | 否 | 最多可以选择的图片张数 | |
| sizeType | Array. |
['original', 'compressed'] | 否 | 所选的图片的尺寸 |
| sourceType | Array. |
['album', 'camera'] | 否 | 选择图片的来源 |
| count | number | 否 | 最多可以选择的图片张数 | |
| success | function | 否 | 接口调用成功的回调函数 | |
| fail | function | 否 | 接口调用失败的回调函数 | |
| complete | function | 否 | 接口调用结束的回调函数(接口调用成功、失败都会执行) |
返参
参数
Object object
| 参数名 | 类型 | 返回值 | 说明 |
|---|---|---|---|
| tempFiles | Array. |
[] | 所选的图片的尺寸 |
| tempFilePaths | Array. |
[] | 选择图片的来源 |
| imageBase64 | String | 当只返回一张图片的时候才会有该字段,如果多选会导致返回json太长 生效版本 好车主 5.56.1 sdk版本 2.2.2 |
更新权限说明
- chooseImage 在sdk2.2.2版本新增了相机/相册授权弹窗 对应app版本5.56.1
返回imageBase64说明
针对有些情况需要拿到图片进行上传,2.2.2版本及其以上可直接获取imageBase64字段上传 如需兼容 H5模式下 可使用input file 标签进行选择图片返回。file标签 ios因特殊性无法新增授权拦截,Android 在app 5.56.1 sdk版本2.2.2版本新增了相机/相册选项的授权弹窗。
调用示例
原生
const _data = {
count: 1,
sizeType: ["original","compressed"],
sourceType: ["album","camera"]
}
wx.chooseImage({
..._data,
success: function (res) {
console.log('chooseImage success, temp path is', res.tempFilePaths[0])
},
fail: function ({ errMsg }) {
console.log('chooseImage fail, err is', errMsg)
}
})
H5
const _data = {
count: 1,
sizeType: ["original","compressed"],
sourceType: ["album","camera"]
}
PAMINA.call('chooseImage', _data, res => {
console.log(res)
}, e => {
console.log(e)
})