可以通过camera来拍照和录像
<view>
<camera device-position="back" flash="off" binderror="error" style="width: 100%; height: 300px;"></camera>
<button type="primary" bindtap="takePhoto">拍照</button>
<button type="primary" bindtap="startRecord">开始录像</button>
<button type="primary" bindtap="stopRecord">结束录像</button>
<image wx:if="{{src}}" mode="widthFix" src="{{src}}"></image>
<video wx:if="{{videoSrc}}" class="video" src="{{videoSrc}}"></video>
</view>
创建和获取camera句柄
onLoad: function (options) {
this.ctx = wx.createCameraContext()
},
拍照
takePhoto() {
this.ctx.takePhoto({
quality: "high",
success: (res) => {
console.log(res)
this.setData({ src: res.tempImagePath })
}
})
},
quality:质量 拍照质量
录像
startRecord() {
this.ctx.startRecord({
success: (res) => {
console.log('startRecord')
}
})
},
stopRecord() {
this.ctx.stopRecord({
success: (res) => {
this.setData({
src: res.tempThumbPath,
videoSrc: res.tempVideoPath
})
}
})
},