Skip to main content
Version: 2.x

CameraContext

参考文档

方法​

startRecord​

开始录像

参考文档

(option: StartRecordOption) => void
参数类型
optionStartRecordOption

API 支持度​

API微信小程序H5React Native
CameraContext.startRecord✔️

stopRecord​

结束录像

参考文档

(option?: StopRecordOption) => void
参数类型
optionStopRecordOption

API 支持度​

API微信小程序H5React Native
CameraContext.stopRecord✔️

takePhoto​

拍摄照片

参考文档

(option: TakePhotoOption) => void
参数类型
optionTakePhotoOption

API 支持度​

API微信小程序H5React Native
CameraContext.takePhoto✔️

onCameraFrame​

获取 Camera 实时帧数据


注: 使用该接口需同时在 camera 组件属性中指定 frame-size。

参考文档

(callback: OnCameraFrameCallback) => CameraFrameListener
参数类型说明
callbackOnCameraFrameCallback回调函数

示例代码​

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

API 支持度​

API微信小程序H5React Native
CameraContext.onCameraFrame✔️

参数​

StartRecordOption​

参数类型必填说明
complete(res: CallbackResult) => void否接口调用结束的回调函数(调用成功、失败都会执行)
fail(res: CallbackResult) => void否接口调用失败的回调函数
success(res: CallbackResult) => void否接口调用成功的回调函数
timeoutCallbackStartRecordTimeoutCallback否超过30s或页面 onHide 时会结束录像

StartRecordTimeoutCallback​

超过30s或页面 onHide 时会结束录像

(result: StartRecordTimeoutCallbackResult) => void
参数类型
resultStartRecordTimeoutCallbackResult

StartRecordTimeoutCallbackResult​

参数类型说明
tempThumbPathstring封面图片文件的临时路径
tempVideoPathstring视频的文件的临时路径

StopRecordOption​

参数类型必填说明
complete(res: CallbackResult) => void否接口调用结束的回调函数(调用成功、失败都会执行)
fail(res: CallbackResult) => void否接口调用失败的回调函数
success(result: StopRecordSuccessCallbackResult) => void否接口调用成功的回调函数

StopRecordSuccessCallbackResult​

参数类型说明
tempThumbPathstring封面图片文件的临时路径
tempVideoPathstring视频的文件的临时路径
errMsgstring调用结果

TakePhotoOption​

参数类型必填说明
complete(res: CallbackResult) => void否接口调用结束的回调函数(调用成功、失败都会执行)
fail(res: CallbackResult) => void否接口调用失败的回调函数
quality"high" | "normal" | "low"否成像质量
success(result: TakePhotoSuccessCallbackResult) => void否接口调用成功的回调函数

TakePhotoSuccessCallbackResult​

参数类型说明
tempImagePathstring照片文件的临时路径,安卓是jpg图片格式,ios是png
errMsgstring调用结果

OnCameraFrameCallback​

回调函数

(result: OnCameraFrameCallbackResult) => void
参数类型
resultOnCameraFrameCallbackResult

OnCameraFrameCallbackResult​

参数类型说明
dataArrayBuffer图像像素点数据,一维数组,每四项表示一个像素点的 rgba
heightnumber图像数据矩形的高度
widthnumber图像数据矩形的宽度

quality​

参数说明
high高质量
normal普通质量
low低质量

API 支持度​

API微信小程序H5React Native
CameraContext.startRecord✔️
CameraContext.stopRecord✔️
CameraContext.takePhoto✔️
CameraContext.onCameraFrame✔️