更新时间:2023-07-28 17:56:34贡献者收藏订阅更新我的文档设置返回文档简介系统相机。 相关 api:my.createcameracontext使用限制●基础库 开始支持,低版本需要做 兼容处理。●需在组件初始化完成后即 onready 回调触发后再执行 my.createcameracontext。使用示例代码.axml 示例代码html复制代码9123456789<camera id="camera" device-position="front" flash="off" style="width: 100%; height: 300px;" onready="oncameraready" onerror="oncameraerror" onstop="oncamerastop"/>.js 示例代码991234567891011121314151617page({ oncameraready(e) { console.log('相机初始化完成'); this.cameracontext = my.createcameracontext('camera'); this.cameracontext.takephoto({ success(res) { console.log(res); } }) }, oncameraerror(e) { console.log('相机发生异常'); }, oncamerastop(e) { console.log('相机终止'); },})属性说明属性类型说明modestring应用模式。 默认值:normal 版本要求:基础库 1.19.0 及以上。device-positionstring摄像头朝向,前置或后置。可选值为 front、back。flashstring闪光灯。可选值为 auto、on、off。 默认值:auto 版本要求:基础库 1.18.0 及以上。output-dimensionstring相机拍照,录制的分辨率。 有效值为 360p、540p、720p、1080p、max。 默认值:720p 版本要求:基础库 1.23.0 及以上。frame-sizestring指定期望的相机帧数据尺寸。 默认值:medium 版本要求:基础库 1.19.0 及以上。onreadyeventhandle相机初始化成功时触发。event.detail = {maxzoom}版本要求:基础库 1.24.3 及以上。 基础库 2.7.16、客户端 10.2.58 开始支持返回 maxzoom。onstopeventhandle摄像头在非正常终止时触发,如页面隐藏、退出小程序、压后台等情况。onerroreventhandle用户不允许使用摄像头时触发。event.detail = { errorcode, errormessage }。onscancodeeventhandle在扫码识别成功时触发,仅在 mode="scancode" 时生效。event.detail = { type, result }。type 为码类型,result 为识别结果。 版本要求:基础库 1.19.0 及以上。mode 的合法值值说明normal相机模式scancode扫码模式device-position 的合法值值说明front前置back后置flash 的合法值值说明auto自动on打开off关闭frame-size 的合法值值说明small小尺寸帧数据 (360 x 640)medium中尺寸帧数据 (540 x 960)large大尺寸帧数据 (720 x 1280)错误码错误码错误描述1001权限校验失败1002磁盘文件相关错误1004无摄像头权限1005无麦克风权限1009扫码时禁止拍照录像1000其他错误