# camera

Start from base library version 1.6.0. Please remaining backward compatible.

WeChat Mac edition: Support

Relevant api: wx.createCameraContext

# Functional description

System camera. Scan QR code function, need to upgrade WeChat client to 6.7.3. NeedUser Authorization scope.camera2.10.0 From initdone Return to Event Max Zoom, Maximum Zoom Range, Related Interface CameraContext.setZoom

# Property Dxplaination

attribute type Default value Required Introductions Minimum version
mode string normal no Application mode, which is only valid at initialization and cannot be dynamically changed 2.1.0
Legal value Introductions
normal Camera mode
scanCode Scan mode
resolution string medium no Resolution, does not support dynamic modification 2.10.0
Legal value Introductions
low low
medium in
high high
device-position string back no Camera towards the 1.0.0
Legal value Introductions
front Antecedent
back to place after
flash string auto no Flashlight, with a value of auto, on, off 1.0.0
Legal value Introductions Minimum version
auto automatic
on open
off Stop
torch Chang Liang 2.8.0
frame-size string medium no Specify the desired camera frame data size 2.7.0
Legal value Introductions
small Small Size Frame Data
medium Medium Size Frame Data
large Large Size Frame Data
bindstop eventhandle no Camera triggered when abnormal termination, such as exit from the background 1.0.0
binderror eventhandle no Triggered when the user is not allowed to use the camera 1.0.0
bindinitdone eventhandle no Triggered when the camera initialization is complete,and.detail = {maxZoom} 2.7.0
bindscancode eventhandle no Triggered when the scan recognition is successful, only in the mode="scanCode" Entered into force at 2.1.0

# Bug & Tip

  1. tip: Only one page can be inserted. camera assembly
  2. tip: Please noteNative Component Usage Restrictions
  3. tip:onCameraFrame Interface according to the frame-size Returns the original frame data of different sizes, with the Camera Components display different images, the actual pixel value is determined by the system

# sample code

Preview with Developer Tool

<!-- camera.wxml -->
<camera device-position="back" flash="off" binderror="error" style="width: 100% height: 300px"></camera>
<button type="primary" bindtap="takePhoto">Photograph</button>
<view>preview</view>
<image mode="widthFix" src="{{src}}"></image>
// camera.js
Page({
  takePhoto() {
    const ctx = wx.createCameraContext()
    ctx.takePhoto({
      quality: 'high',
      success: (res) => {
        this.setData({
          src: res.tempImagePath
        })
      }
    })
  },
  error(e) {
    console.log(and.detail)
  }
})