兄弟, 是canvas2D的绘图接口有问题 不要用canvasContext.createImageData 改用canvas.createImageData
Android 端微信8.0.37 onCameraFrame回调的frame数据有问题了?Android 端微信8.0.37 onCameraFrame回调的frame数据内容有问题,数据长度看起来是对的,但是经过转换后存储完是黑图,8.0.35和8.0.33都没有问题,请问这是什么问题?怎么解决?多谢! 复现问题的代码片段: https://developers.weixin.qq.com/s/OuEujLmO7UIl 现在这个问题发生在线上,麻烦抓紧看看是不是相关升级导致API变动的问题?具体是哪个API,怎么修复,麻烦告知,谢谢!
2023-06-07同问
wx.canvasToTempFilePath花费的时间为什么越来越长?需求是,通过监听onCameraFrame方法不断获取相机实时帧数据转换成jpg图片并不断上传,采用如下代码方法,现在发现因为 wx.canvasToTempFilePath花费的时间越来越长,导致画面越来越卡。。。。。。。。图一刚开始,图二是中间,图三是十秒后 this.listener = camera_ctx.onCameraFrame((frame) => { // nCounter等于30 是因为一开始相机会有一个对焦的过程,如果一开始获取数据,就是模糊的图片 if (nCounter == 10) { // console.log('nCounter+30结束'); timeadd2 = new Date() console.log('nCounter+30时间为: '); console.log(this.timeFormat(timeadd1, timeadd2)); console.log('实时帧高宽度-----------------------'); console.log('宽度:' + frame.width + ' ' + '高度: ' + frame.height) //将实时帧像素数据格式转换成Uint8ClampedArray var data = new Uint8Array(frame.data); var clamped = new Uint8ClampedArray(data); // 实时帧数据添加到Canvas上 //将实时帧数据添加到画布 getImgData(data, width, height) { // console.log('进入到将像素数据添加到画布'); // console.log(this.timeFormat(new Date())); timecanva1 = new Date() wx.canvasPutImageData({ canvasId: 'firstCanvas', x: 0, y: 0, width: width, height: height, data: data, success: res => { // console.log('成功将像素数据添加到画布----------'); // console.log(this.timeFormat(new Date())); timecanva2 = new Date() console.log('像素数据添加到画布时间为: '); console.log(this.timeFormat(timecanva1, timecanva2)); // console.log(res); //将画布移动到临时图片 getImgPath(width, height) { // console.log('进入canvans转换为临时图片'); // console.log(this.timeFormat(new Date())); timeImg1 = new Date() let that = this wx.canvasToTempFilePath({ x: 0, y: 0, width: width, height: height, canvasId: 'firstCanvas', fileType: 'jpg', destWidth: width, destHeight: height, // 图片的质量 quality: 0.1, success: res => { that.canvasContext.clearRect(0, 0, width, height); console.log('清除后canvasContext-------------------'); console.log(that.canvasContext); // console.log('成功将canvans转换为临时图片------------'); // console.log(this.timeFormat(new Date())); timeImg2 = new Date() console.log('canvans转换为临时图片时间为:'); console.log(this.timeFormat(timeImg1, timeImg2)); that.setData({ restempFilePath: res.tempFilePath }); that.upLoadImg(res.tempFilePath) }, fail(res) { console.log('获取canvans图片失败'); console.log(res); } }, this) }, } }) }, } nCounter++ }) [图片][图片][图片]
2023-05-24