- 采用新版canvas接口,相机实时获取帧数据后通过canvas转为base64后发现图片全是黑色?
fitness:function(){ var that = this var camera_ctx = wx.createCameraContext() const listener = camera_ctx.onCameraFrame((frame) => { console.log(frame.data instanceof ArrayBuffer, frame.width, frame.height) console.log("开始处理") const query = wx.createSelectorQuery() query.select('#myCanvas') .fields({ node: true, size: true }) .exec((res) => { const canvas = res[0].node canvas.width = frame.width canvas.height = frame.height console.log(canvas.width) console.log(canvas.height) var data = new Uint8Array(frame.data); var clamped = new Uint8ClampedArray(data); console.log("实时帧数据添加到Canvas上") const context1 = canvas.getContext('2d') context1.putImageData(clamped, 0, 0, 0, 0, frame.width, frame.height) wx.canvasToTempFilePath({ x: 0, y: 0, width: frame.width, height: frame.height, canvas: canvas, fileType: 'jpg', destWidth: frame.width, destHeight: frame.height, // // 精度修改 // quality:1, success(res) { // 临时文件转base64 wx.getFileSystemManager().readFile({ filePath: res.tempFilePath, //选择图片返回的相对路径 encoding: 'base64', //编码格式 success: function(res){ // 保存base64 console.log("获取的base64数据:",res.data) that.data.mybase64 = res.data; }, fail:function(error){ console.log("error",error) } }) }, fail:function(error) { console.log("临时文件转base64失败",error); } }, that) console.log("开始传输") wx.request({ url: 'http://192.168.43.40:8080/predicts' , method: 'POST', data: {base64Img:that.data.mybase64} , // dataType:'json', header: { 'content-type': 'application/x-www-form-urlencoded'//自定义请求头信息 }, success:function(res){ console.log('===result===',res) }, fail:function(error){ console.log("传输失败",error) } }) }) }) listener.start({ success(res){ console.log("开始监听") } }) }, [图片]
04-07 - 使用onCameraFrame来实时获取帧,但真机测试后发现并没有监听而且报错 如何解决?
啊啊啊啊啊啊啊啊啊啊之前还行的,现在跑了之后发现后台完全没获取到数据 [图片] [图片]
04-03