图片选择
chooseImage
图片选择参数说明
| 属性 | 类型 | 默认值 | 是否必填 | 描述 |
|---|---|---|---|---|
count | number | 9 | 否 | 最多可以选择的图片张数 |
sourceType | string | album | 否 | album (相册) 或 camera (摄像头) |
sizeType | string | compressed | 否 | original (原图) 或 compressed (压缩图) |
quality | number | 90 | 否 | sizeType 为 compressed 时有效 压缩质量(百分比数值) 10 ~ 100 |
success | function | 否 | 接口调用成功的回调函数 | |
fail | function | 否 | 接口调用失败的回调函数 | |
complete | function | 否 | 接口调用结束的回调函数(调用成功、失败都会执行) |
object.success 回调函数
| 属性 | 类型 | 说明 |
|---|---|---|
| tempFilePaths | [] | 图片的本地临时文件路径列表 (本地路径) |
示例代码
dsBridge.call(
'chooseImage',
{
count: 9,
sourceType: 'album',
sizeType: 'compressed',
quality: 90,
success (res) {
// tempFilePath可以作为img标签的src属性显示图片
const tempFilePaths = res.tempFilePaths
}
}
)
本地图片裁剪参数
tip
由于本地图片过大会导致页面卡顿,所以需要通过裁剪参数返回缩略图
参数说明
| 属性 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| width | number | 图片宽度 | |
| height | number | 图片高度 | |
| mode | number | 1 | 1 或 2 或 3 |
| strip | boolean | true | true 或 false |
| quality | number | 90 | 图片压缩质量 10 ~ 100 (百分比数值) |
缩略图裁剪方式
裁剪正中部分,等比缩小生成 200x200 缩略图
https://localfiles/img_20210810100700.jpg?mode=1&width=200&height=200
宽度固定为 200px,高度等比缩小,生成 200 x auto 缩略图
https://localfiles/img_20210810100700.jpg?20191111100700.jpg?mode=2&width=200
高度固定为 200px,宽度等比缩小,生成 auto x 200 缩略图
https://localfiles/img_20210810100700.jpg?20191111100700.jpg?mode=3&height=200