# camera

相机组件。相关 的api介绍:qa.createCameraContext

属性 类型
默认值
必填
说明
resolution string medium 分辨率,不支持动态修改
device-position string back 摄像头朝向
flash string auto 闪光灯,值为auto, on, off, torch
frame-size string medium 指定期望的相机帧数据尺寸
bindstop eventhandle 摄像头在非正常终止时触发,如退出后台等情况
binderror eventhandle 用户不允许使用摄像头时触发
bindinitdone eventhandle 相机初始化完成时触发

resolution 的合法值

说明
low
medium
high

device-position 的合法值

说明
front 前置
back 后置

flash 的合法值

说明
auto 自动
on 打开
off 关闭
torch 常亮

frame-size 的合法值

说明
small 小尺寸帧数据
medium 中尺寸帧数据
large 大尺寸帧数据

# Bug & Tip

tip: 同一页面只能插入一个 camera 组件 tip:onCameraFrame 接口根据 frame-size 返回不同尺寸的原始帧数据,与 Camera 组件展示的图像不同,其实际像素值由系统决定

# 示例代码

<view class="section tc">
 <camera
        id="myCamera"
        class="camerastyle"
        device-position="{{deviceposition}}"
        flash="{{flash}}"
        frame-size="{{photoQuality}}"
        resolution="{{photoQuality}}"
        bind:error="binderror"
        bind:stop="bindstop"
        bind:cameraframe="bindcameraframe"
        bind:initdone="bindinitdone"
      ></camera>
</view>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
Page({
  data: {
     context:{},
	 imageurl:''
  },
  onTakePhotoClick() {
    let that = this
    context = qa.createCameraContext()
    context.takePhoto({
        quality: 'low',
        success(data){
          that.setData({
            imageurl: data.tempImagePath
          })
          console.log('xxx  onTakePhotoClick success  url : ' + data.tempImagePath)
        },
        fail(){
          console.log('xxx  onTakePhotoClick fail')
        },
        complete(){
          console.log('xxx  onTakePhotoClick complete')
        }
      })
   }
})
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25

在线客服