Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

WeChat Small Program API Camera CameraContext instance


May 18, 2021 WeChat Mini Program Development Document


Table of contents


CameraContext

CameraContext instance, available at wx.createCameraContext.

CameraContext is bound to the unique camera component within the page, which operates the corresponding camera component.



Method:

CameraFrameListener CameraContext.onCameraFrame(function callback)

Base library 2.7.0 starts to support, and low versions need to be compatible.

Get Camera real-time frame data

Parameters

function callback

Callback function

Parameters

Object res
Property Type Description
width number The width of the image data rectangle
height number The height of the image data rectangle
data ArrayBuffer Image pixel data, a one-dimensional array, each of which represents a pixel rgba

Returns a value

CameraFrameListener

Note: Using this interface requires specifying frame-size in the camera component properties at the same time.

The sample code

const context = wx.createCameraContext()
const listener = context.onCameraFrame((frame) => {
  console.log(frame.data instanceof ArrayBuffer, frame.width, frame.height)
})
listener.start()


CameraContext.setZoom(Object object)

Base library 2.10.0 starts to support, and low versions need to be compatible.

Set the zoom level

Parameters

Object object

Property Type The default Required Description
zoom number Is Zoom level, range 1, maxZoom. Z oom is desirable for a small number, accurate to the next place in the count. MaxZoom is available in the bindinitdone return value.
success function Whether The interface calls a successful callback function
fail function Whether The interface calls the failed callback function
complete function Whether Callback function at end of interface call (call succeeds, fails are executed)

object.success callback function

Parameters
Object res
Property Type Description
zoom number The zoom level that is actually set. Due to system limitations, some models may not be able to set a specified value and will use the nearest setable value between.


CameraContext.startRecord(Object object)

Start recording

Parameters

Object object

Property Type The default Required Description
timeoutCallback function Whether The recording ends when more than 30s or the page onHide
success function Whether The interface calls a successful callback function
fail function Whether The interface calls the failed callback function
complete function Whether Callback function at end of interface call (call succeeds, fails are executed)

object.timeoutCallback callback function

Parameters
Object res
Property Type Description
tempThumbPath string Temporary path to cover picture file (local path)
tempVideoPath string Temporary path for video files (local path)


CameraContext.stopRecord(Object object)

End the recording

Parameters

Object object

Property Type The default Required Description
compressed boolean false Whether Start video compression, which works the same chooseVideo
success function Whether The interface calls a successful callback function
fail function Whether The interface calls the failed callback function
complete function Whether Callback function at end of interface call (call succeeds, fails are executed)

object.success callback function

Parameters
Object res
Property Type Description
tempThumbPath string Temporary path to cover picture file (local path)
tempVideoPath string Temporary path for video files (local path)


CameraContext.takePhoto(Object object)

Take a photo

Parameters

Object object

Property Type The default Required Description
quality string normal Whether Image quality
success function Whether The interface calls a successful callback function
fail function Whether The interface calls the failed callback function
complete function Whether Callback function at end of interface call (call succeeds, fails are executed)

The legal value of object.quality

Value Description The lowest version
high Quality
normal Ordinary quality
low Low quality

object.success callback function

Parameters
Object res
Property Type Description
tempImagePath string Photo file temporary path (local path), Android is jpg picture format, ios is png