当没有使用插件,直接在当前Page采用如下代码就能完成拍照:
const ctx = wx.createCameraContext();
ctx.takePhoto({
quality: 'high',
success: (res) => {
console.log("拍照");
this.setData({
src: res.tempImagePath
})
wx.previewImage({
urls: [this.data.src],
})
},
fail:(res) => {
console.log(res)
},
complete:(res)=>{
console.log(res)
}
})
但如果camera组件在插件中,当前Page调用插件使用Camera,直接采用如上代码,无法完成拍照,也没有错误提示。需要在插件中增加输出接口,如下:
module.exports = {
......
getCameraContext:function(){
return wx.createCameraContext()
}
}
然后将默认的创建摄像头上下文wx.createCameraContext()替换为plugin.getCameraContext(),即能成功拍照了。