Skip to content

Camera

createCameraContext

TIP

The API usage is as follows: CameraContext wx.createCameraContext()

  • Functional description: Create the camera context CameraContext object
  • Return value: CameraContext

CameraContext

  • Functional description: CameraContext instance, which can be wx.createCameraContext Get. cameraContext and the only one in the page camera Component binding, operation corresponding camera Component

.onCameraFrame

TIP

The API usage is as follows: CameraFrameListener CameraContext.onCameraFrame(onCameraFrameCallback callback)

TIP

To use this interface, you must camera Specify frame-size in component properties

  • Functional description: Get the Camera real-time frame data.

  • Return value: function callback。

  • object.success callback function parameters: Object res。

    PropertiesTypeDescription
    widthnumberThe width of the image data rectangle
    heightnumberThe height of the image data rectangle
    dataArrayBufferImage pixel data, one-dimensional array, each four items represent the rgba of a pixel
  • Return value: CameraFrameListener

  • Sample code:

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

.setZoom

TIP

The API usage is as follows: CameraContext.setZoom(Object object)

  • Functional description: Set the zoom level.

  • Parameters and descriptions: Object object

    PropertiesTypeDefault valueRequiredDescription
    zoomnumber-YesZoom level, range [1, maxZoom]. zoom can be a decimal, accurate to one decimal place. maxZoom can be obtained from the bindinitdone return value
    successFunction-NoCallback function for successful interface call
    failFunction-NoCallback function for failed interface call
    completeFunction-NoCallback function for interface call completion (executed regardless of success or failure)
  • object.success callback function parameters: Object res。

    PropertiesTypeDescription
    zoomnumberThe actual zoom level set. Due to system limitations, some models may not be able to be set to the specified value, and the closest settable value will be used instead

.startRecord

TIP

The API usage is as follows: CameraContext.startRecord(Object object)

  • Functional description: Start recording.

  • Parameters and descriptions: Object object

    PropertiesTypeDefault valueRequiredDescription
    timeoutCallbackfunction-NoThe recording will end when the time exceeds 30 seconds or the page onHide is called. This callback will also be triggered when the recording is abnormally exited.
    successFunction-NoCallback function for successful interface call
    failFunction-NoCallback function for failed interface call
    completeFunction-NoCallback function for interface call completion (executed regardless of success or failure)
  • object.timeoutCallback callback function parameters: Object res。

    PropertiesTypeDescription
    tempThumbPathstringThe temporary path of the cover image file
    tempVideoPathstringThe temporary path of the video file

.stopRecord

TIP

The API usage is as follows: CameraContext.stopRecord(Object object)

  • Functional description: End recording.

  • Parameters and descriptions: Object object

    PropertiesTypeDefault valueRequiredDescription
    successFunction-NoCallback function for successful interface call
    failFunction-NoCallback function for failed interface call
    completeFunction-NoCallback function for interface call completion (executed regardless of success or failure)
  • object.success callback function parameters: Object res。

    PropertiesTypeDescription
    tempThumbPathstringThe temporary path of the cover image file
    tempVideoPathstringThe temporary path of the video file

.takePhoto

TIP

The API usage is as follows: CameraContext.takePhoto(Object object)

  • Functional description: Take a photo.

  • Parameters and descriptions: Object object

    PropertiesTypeDefault valueRequiredDescription
    qualitystringnormalNoImage quality
    successFunction-NoCallback function for successful interface call
    failFunction-NoCallback function for failed interface call
    completeFunction-NoCallback function for interface call completion (executed regardless of success or failure)
  • Legal values

    ValueDescription
    highHigh quality
    normalNormal quality
    lowLow quality
  • object.success callback function parameters: Object res。

    PropertiesTypeDescription
    tempImagePathstringThe temporary path (local path) of the photo file, jpg image format for Android and png for iOS

CameraFrameListener

TIP

  • The listener returned by CameraContext.onCameraFrame()
  • For related documents, see camera

.start

TIP

The API usage is as follows: CameraFrameListener.start(Object object)

  • Functional description: Start listening to frame data.

  • Parameters and descriptions: Object object

    PropertiesTypeDefault valueRequiredDescription
    successFunction-NoCallback function for successful interface call
    failFunction-NoCallback function for failed interface call
    completeFunction-NoCallback function for interface call completion (executed regardless of success or failure)

.stop

TIP

The API usage is as follows: CameraFrameListener.stop(Object object)

  • Functional description: Stop listening to frame data.

  • Parameters and descriptions: Object object

    PropertiesTypeDefault valueRequiredDescription
    successFunction-NoCallback function for successful interface call
    failFunction-NoCallback function for failed interface call
    completeFunction-NoCallback function for interface call completion (executed regardless of success or failure)