发布日:2022-03-14 20:51 阅读数:
<camera style="width: 100%; height: 450px;"></camera>当然这行代码仅仅实现了相机在小程序内显示,无法实现更多功能,我们可以参考官方文档来实现更多功能。
属性名 |
类型 |
默认值 |
说明 |
---|---|---|---|
mode |
String |
normal |
有效值为 normal, scanCode |
device-position |
String |
back |
前置或后置,值为front, back |
flash |
String |
auto |
闪光灯,值为auto, on, off |
bindstop |
EventHandle |
|
摄像头在非正常终止时触发,如退出后台等情况 |
binderror |
EventHandle |
|
用户不允许使用摄像头时触发 |
bindscancode |
EventHandle |
|
在扫码识别成功时触发,仅在 mode="scanCode" 时生效 |
<camera device-position="front" flash="on" style="width: 100%; height: 450px;"></camera>
属性 |
类型 |
默认值 |
是否必填 |
说明 |
---|---|---|---|---|
quality |
string |
normal |
否 |
成像质量 |
success |
function |
|
否 |
接口调用成功的回调函数 |
fail |
function |
|
否 |
接口调用失败的回调函数 |
complete |
function |
|
否 |
接口调用结束的回调函数(调用成功、失败都会执行) |
takePhoto(){ },这是第一步,创建一个takePhoto函数,接下来,我们调用小程序相机的API。
takePhoto(){ const ctx = wx.createCameraContext() },创建ctx对象,该对象为wx.createCameraContext()函数。接下来,需要调用createCameraContext()的takePhoto组件。
takePhoto(){ const ctx = wx.createCameraContext() ctx.takePhoto({ }) },接下来,参考上表,我们设置我们所需要的参数。
takePhoto() { const ctx = wx.createCameraContext() ctx.takePhoto({ quality: 'high', success: (res) => { this.setData({ src: res.tempImagePath }) } }) },
<camera device-position="front" flash="on" style="width: 100%; height: 450px;"></camera> <button type="primary" bindtap="takePhoto">拍照</button> <image mode="widthFix" src="{{src}}"></image>
编辑:航网科技 来源:腾讯云
本文版权归原作者所有 转载请注明出处
Copyright © 2011-2020 www.hangw.com. All Rights Reserved 深圳航网科技有限公司 版权所有 增值电信业务经营许可证:粤B2-20201122 - 粤ICP备14085080号
微信扫一扫咨询客服
全国免费服务热线
0755-36300002