遇到同样的问题,
canvas 2d,wx.canvasToTempFilePath保存jpg文件变大?3647×2086,2.44M的jpg文件,我在Canvas 2d中用1920×1098绘制,wx.canvasToTempFilePath保存后,文件大小变成了4.087M,更换手机型号,大小有小量的变化。代码如下: var canvas = param._this.data.imgCavObj; canvas.width = param.size.canvas_w * param._this.data.dpr; canvas.height = param.size.canvas_h * param._this.data.dpr; var ctx = param._this.data.imgCtx; ctx.scale(param._this.data.dpr, param._this.data.dpr); ctx.clearRect(0, 0, param.size.canvas_w, param.size.canvas_h); var img = param._this.data.cavImg; img.src = param.imgpath; img.onload = () => { ctx.drawImage(img, 0, 0, param.size.canvas_w, param.size.canvas_h); wx.canvasToTempFilePath({ destWidth: param.size.canvas_w, destHeight: param.size.canvas_h, canvas: canvas, fileType: "jpg", quality: 0.3, success: function (res) { if (param.success) param.success(res); }, fail: function (res) { if (param.fail) param.fail(res); } }, param._this); } 我想要的是文件大小变小,结果变大了。改变quality,文件大小也没有变化。
2021-09-15