# takePhoto ^7.8
拍照功能,并返回相片数据
# 请求参数
Prop | Type | Requierd | Default | Comment |
---|---|---|---|---|
compressRage | Number | N | 100 | 返回照片的压缩率,范围为0~100(只是针对jpg格式的图片,png格式没有压缩率),数值越高保真率越高 |
type | String | N | jpg | 值为jpg或png,指定返回相片的格式 |
isNeedBase64 | Boolean | Y | false | 是否需要返回相片base64数据(8.12后统一默认false,为兼容旧版,建议必填) |
allowEidt | Number | N | 0 | 是否允许拍照后使用裁剪框编辑图片,0:不可编辑,1:可编辑(^8.10) |
# 接口调用示例
const params = {
compressRage: 80,
type: 'jpg',
isNeedBase64: true,
}
this.$bridge
.takePhoto(params)
.then(res => {
this.$alert(res)
})
.catch(err => {
this.$toast(err)
})
1
2
3
4
5
6
7
8
9
10
11
12
13
14
2
3
4
5
6
7
8
9
10
11
12
13
14
TIP
设置 isNeedBase64
: true
时,会带来一定的卡顿现象,此时正在将本地路径转换为base64
# 返回参数
Prop | Type | Requierd | Default | Comment |
---|---|---|---|---|
status | Number | Y | N/A | 0-拍照成功,1-取消拍照 |
type | String | N | jpg | 相片的格式 |
data | String | N | N/A | 如果isNeedBase64为true,则返回相片的base64字符串,返回中带有相应的前缀:"data:image/jpg;base64,..."" |
filePath | String | N | N/A | 返回相片保存的文件路径 |
fileName | String | N | N/A | 保存的文件名 |
size | Number | N | N/A | 返回相片的文件大小,带小数,单位为Kb |
# 接口返回示例
// 成功拍照
{
status: 0,
type: "jpg",
filePath: "xxxxx",
fileName: "xxx.jpg",
size: 100
}
// 取消拍照
{
errorCode: -1,
msg: '摄像头没有权限'
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
2
3
4
5
6
7
8
9
10
11
12
13
14