场景时需要将图片压缩到1M以内,但是这个方法怎么不起作用了??
//----------绘制图形并取出图片路径--------------
var ctx = wx.createCanvasContext('canvas', that)
ctx.drawImage(res.path, 0, 0, canvasWidth, canvasHeight)
console.log(3344)
ctx.draw(false, () => {
//留一定的时间绘制canvas
console.log(1100)
setTimeout(() => {
console.log(2222)
wx.canvasToTempFilePath({
canvasId: 'canvas',
destWidth: canvasWidth,
destHeight: canvasHeight,
success:(res) => {
console.log(1)
console.log(res.tempFilePath) //最终图片路径
},
fail: (res) => {
console.log(2)
console.log(res.errMsg)
}
}, that)
}, 5000)
})