ar-camera
基础库 3.15.104 开始支持,低版本需做兼容处理。
解释:AR相机,在DuMixAR内容开放平台( http://dumix.baidu.com/content#/ )提交并上线AR项目后(选择“百度App-相机”渠道)获取到AR Key、AR Type,可配置展现。
属性说明:
属性名 | 类型 | 默认值 | 说明 |
---|---|---|---|
key | String | - | AR项目唯一标识,在DuMixAR内容开放平台上传生成AR项目后获取AR Key |
type | String | - | AR相机类型,在DuMixAR内容开放平台上传生成AR项目后获取AR Type:2D 跟踪类型:0;SLAM 类型:5;IMU 类型:8。 |
flash | String | off | 闪光灯,值为auto, on, off |
binderror | EventHandle | - | 用户不允许使用摄像头时触发 |
bindload | EventHandle | - | AR加载成功时触发 |
bindmessage | EventHandle | - | 开发者制作AR项目时可自定义按键,用户点击时会收到事件和数据 |
说明:
- ar-camera 组件是由客户端创建的原生组件,它的层级是最高的,不能通过 z-index 控制层级。可使用 cover-view cover-image 覆盖在上面。
- 同一页面只能插入一个 ar-camera 组件。可在新页面中放置ar-camera组件,并使用 swan.navigate API(注意应防止用户多次连续点击,否则会导致AR页面多次打开出现卡顿)跳转至该页面。
- 请勿在 scroll-view、swiper、picker-view、movable-view 中使用 ar-camera 组件。
- 相关API:createARCameraContext
示例:
- <ar-camera key="xx" type="x" bindmessage="message" binderror="error" style="width: 100%; height: 300px;"></ar-camera>
<button type="primary" bind:tap="takePhoto">拍照</button>
<view>预览</view>
<image mode="widthFix" src="{{src}}"></image>
- Page({
takePhoto() {
const ctx = swan.createARCameraContext();
ctx.takePhoto({
success: (res) => {
this.setData({
src: res.tempImagePath
})
}
});
},
error(e) {
console.log(e.detail);
},
message(e) {
console.log(e.detail);
}
});