const ctx = wx.createCanvasContext(‘myCanvas’);
let canvasW = 525;
let canvasH = 420;
// 将图片绘制到画布
// drawImage(string imageResource, number dx, number dy, number dWidth, number dHeight, number sx, number sy, number sWidth, number sHeight);
ctx.drawImage(src, 0, 0, 300, 200);
//必须要用到, 并且需要在绘制成功后导出图片
ctx
.
draw(false, function() {
// 导出图片
wx.canvasToTempFilePath({
width: canvasW,
height: canvasH,
destWidth: canvasW,
destHeight: canvasH,
canvasId: ‘myCanvas’,
fileType: ‘jpg’,
success: function(res) {
// res.tempFilePath为导出的图片路径
typeof cb == ‘function’ && cb(res.tempFilePath);
console.log(“裁剪完毕”);
return false;
}
});
});
首次执行该段代码,canvas显示出图片
第二次执行该段代码,canvas不显示图片,调试发现ctx.draw()第二次没有执行,什么原因?