# uni.createCameraContext()

Create and return the context cameraContext object of the camera component.

Platform Difference Description

App H5 微信小程序 支付宝小程序 百度小程序 抖音小程序 飞书小程序 QQ小程序 快手小程序 京东小程序
x x x

This API is the js API supporting the camera component, which has the same platform compatibility as the camera component, and can realize a non-full-screen camera. The app can realize full-screen camera through plus.camera.

cameraContext object method list

Method Parameter Description Platform Difference Description
takePhoto Object Take a photo, you can specify the quality, and return the path of the image if it succeeds.
setZoom Object 设置缩放级别。 百度、QQ、快手、京东小程序不支持
startRecord Object 开始录像
stopRecord Object 结束录像,成功则返回封面与视频。
onCameraFrame Function 获取 Camera 实时帧数据。 微信小程序详情、支付宝小程序详情、抖音小程序支持详情

# cameraContext.takePhoto

takePhoto Object parameter list:

Parameter Type Required Description
quality String No Imaging quality, the value is high (high quality), normal (normal quality), low (low quality), the default is normal
selfieMirror Boolean No Whether to enable mirroring, the default is true. Only supported by WeChat MiniApp 2.22.0+
success Function No The interface calls the callback function successfully, returns the temporary path of the photo file, res = { tempImagePath }
fail Function No Callback function for interface call failure
complete Function No The callback function for the end of the interface call (it will be executed when the call succeeds or fails)

# cameraContext.setZoom

setZoom Object parameter list:

Parameter Type Required Description
zoom String yes zoom level, range [1, maxZoom]. zoom can take a decimal, accurate to one decimal place. maxZoom is available in @initdone return value.
success Function No Callback function for successful interface call
fail Function No Callback function for interface call failure
complete Function No The callback function for the end of the interface call (it will be executed when the call succeeds or fails)

# cameraContext.startRecord

StartRecord's Object parameter list:

Parameter Type Required Description
timeoutCallback Function No The recording will end when the connection exceeds 30s or the page is onHide
timeout Number No The upper limit of the recording time, in seconds, the default is 30s. The maximum recording time for WeChat MiniApp cannot exceed 5 minutes, and the maximum recording time for Alipay MiniApp is 10 minutes. Only supported by WeChat 2.22.0+ and Alipay 1.11.0+ MiniApp
selfieMirror Boolean No Whether to enable mirroring, the default is true. Only supported by WeChat MiniApp 2.22.0+
success Function No Callback function for successful interface call
fail Function No Callback function for interface call failure
complete Function No The callback function for the end of the interface call (it will be executed when the call succeeds or fails)

# cameraContext.stopRecord

stopRecord Object parameter list:

Parameter Type Default Required Description
compressed Boolean false 启动视频压缩,压缩效果同 chooseVideo 。微信2.10.0+ 、抖音2.41.0(Android暂不支持)、快手小程序支持
success Function No Interface calls the callback function successfully, returns the temporary path of the cover and video, res = { tempThumbPath, tempVideoPath }.
fail Function No Callback function for interface call failure
complete Function No The callback function for the end of the interface call (it will be executed when the call succeeds or fails)

Notice

  • To realize OCR and other document identification requirements under the App, you can obtain native plug-ins in the plug-in market, [https://ext.dcloud.net.cn/plugin?id=135](https://ext.dcloud.net.cn /plugin?id=135)
  • To realize OCR and other document identification requirements under the WeChat MiniApp, the plug-in market also has packaging, search ocr to see.
  • You can use the user authorization API to determine whether the user has granted the camera access to the application https://uniapp.dcloud.io/api/other/authorize
  • Different MiniApp platforms may have different API implementations. For example, Alipay MiniApp needs to pass the parameter cameraId when calling createCameraContext. Please refer to the specific document when using it.
  • The Alipay MiniApp Developer Tool (IDE) does not support debugging this API at the moment, please use the real device debugging function to debug on a real device.