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++
})