需求是,通过监听onCameraFrame方法不断获取相机实时帧数据转换成jpg图片并不断上传,采用如下代码方法,现在发现因为 wx.canvasToTempFilePath花费的时间越来越长,导致画面越来越卡。。。。。。。。图一刚开始,图二是中间,图三是十秒后
this.listener = camera_ctx.onCameraFrame((frame) => {
if (nCounter == 10) {
timeadd2 = new Date()
console.log('nCounter+30时间为: ');
console.log(this.timeFormat(timeadd1, timeadd2));
console.log('实时帧高宽度-----------------------');
console.log('宽度:' + frame.width + ' ' + '高度: ' + frame.height)
var data = new Uint8Array(frame.data);
var clamped = new Uint8ClampedArray(data);
getImgData(data, width, height) {
timecanva1 = new Date()
wx.canvasPutImageData({
canvasId: 'firstCanvas',
x: 0,
y: 0,
width: width,
height: height,
data: data,
success: res => {
timecanva2 = new Date()
console.log('像素数据添加到画布时间为: ');
console.log(this.timeFormat(timecanva1, timecanva2));
getImgPath(width, height) {
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);
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++
})
同问
请问有解决吗,我也碰到了这个问题,用canvans画图后,时间越来越久