cameracontext.takephoto(object object)
基础库 或更高版本; 若版本较低,建议采取 兼容处理 。
支小宝客户端 支持
安诊儿客户端 支持
小程序开发者工具: 不支持。请以真机的调试结果为准。
主体: 企业支付宝小程序 、 个人支付宝小程序
相关文档: camera 组件
拍摄照片。
object object
属性 | 类型 | 默认值 | 必填 | 描述 | |||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
quality | string | normal | 否 | 成像质量 |
|||||||||||||
|
|||||||||||||||||
success | function | - | 否 | 调用成功的回调函数 |
|||||||||||||
fail | function | - | 否 | 调用失败的回调函数 |
|||||||||||||
complete | function | - | 否 | 调用结束的回调函数(调用成功、失败都会执行) |
success 回调函数
参数
object res
属性 | 类型 | 兼容性 | 描述 |
---|---|---|---|
tempimagepath | string | - | 照片文件的临时路径 |
width | number | 支付宝: 10.5.36 |
照片宽度,单位为 px |
height | number | 支付宝: 10.5.36 |
照片高度,单位为 px |
size | number | 支付宝: 10.5.36 |
照片大小。单位:字节(b) |
cameracontext.takephoto(object object)
检测文件真实类型
success 回调参数
.axml
.js
<camera
id="camera"
flash="off"
frame-size="medium"
device-position="back"
onready="oncameraready"
style="width: 100%; height: 300px"
/>;
page ({
oncameraready (e) {
this.cameracontext = my.createcameracontext ('camera');
this.cameracontext.takephoto ({
quality: 'high',
success (res) {
console.log (res);
},
fail (err) {
console.log (err);
},
});
},
});
this.cameracontext.takephoto ({
quality: 'high',
success (res) {
console.log (res);
my.detectfiletype ({
filepath: res.tempimagepath,
success (res) {
console.log ('detectfiletype: success', res);
},
fail (err) {
console.log ('detectfiletype: fail', err);
},
});
},
fail (err) {
console.log (err);
},
});
{
"success": "true",
"tempimagepath": "https://resource/4a13ecc7c7d560d052f430bc35a687da3.image",
"height": 1280
"width": 720
"size": 18920
}
-
tip
照片的文件地址文件扩展名并非为文件真实类型,在真机上扩展名是 .image。
若需判断文件实际扩展名,可使用 [my.detectfiletype](https://opendocs.alipay.com/mini/076dwu?pathhash=c64d1eb5) 进行查询,请以此接口返回结果为准,不过需注意此接口仅限真机调试,可参考上方 [示例代码]{demo1}。