• camera
    • Bug & Tip

    camera

    系统相机。该组件是原生组件,使用时请注意相关限制。

    需要用户授权 scope.camera

    属性名类型默认值说明最低版本
    modeStringnormal有效值为 normal, scanCode
    device-positionStringback前置或后置,值为front, back
    flashStringauto闪光灯,值为auto, on, off
    bindstopEventHandle摄像头在非正常终止时触发,如退出后台等情况
    binderrorEventHandle用户不允许使用摄像头时触发
    bindscancodeEventHandle在扫码识别成功时触发,仅在 mode="scanCode" 时生效

    相关api:qq.createCameraContext

    Bug & Tip
    • 请注意原生组件使用限制。
    • tip: 同一页面只能插入一个 camera 组件。示例:
    1. <!-- camera.qml -->
    2. <camera
    3. device-position="back"
    4. flash="off"
    5. binderror="error"
    6. style="width: 100%; height: 300px;"
    7. ></camera>
    8. <button type="primary" bindtap="takePhoto">拍照</button>
    9. <view>预览</view>
    10. <image mode="widthFix" src="{{src}}"></image>
    // camera.js
    Page({
      takePhoto() {
        const ctx = qq.createCameraContext()
        ctx.takePhoto({
          quality: 'high',
          success: (res) => {
            this.setData({
              src: res.tempImagePath
            })
          }
        })
      },
      error(e) {
        console.log(e.detail)
      }
    })