wx.drawImage画出的图片空白

发布于 6 年前作者 lijing1291 次浏览最后编辑 6 年前来自 ask

const ctx = wx.createCanvasContext(‘mycanvas’);

//绘制上传的图片(that.data.tempFilePaths的值是相册选择的临时路径)

ctx.drawImage(that.data.tempFilePaths, 0, 0, 600, that.data.height);

console.log(“生成临时图片之前:” + that.data.tempFilePaths)

let x = ‘’;

ctx.draw(false, wx.canvasToTempFilePath({

canvasId: ‘mycanvas’,

success: function (res) {

console.log(res)

that.setData({

tempSavePath: res.tempFilePath

});

}

}));

2 回复
liaoxiulan
liaoxiulan1 楼6 年前

你好,请具体描述问题出现的流程,并提供能复现问题的简单代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html)。

xiuying18
xiuying182 楼4 年前

我找到原因了是因为

ctx.draw(true, wx.canvasToTempFilePath({

canvasId: 'mycanvas',

success: function (res) {

console.log(res)

that.setData({

tempSavePath: res.tempFilePath

});

}

}));

这个地方的回掉函数虽然执行了而且sucess里面的也执行了但是res的临时链接没有画出来。然后我看了下文档是会掉函数所以我改成

ctx.draw(true, function () {

wx.canvasToTempFilePath({

canvasId: ‘mycanvas’,

success: function (res) {

console.log(res)

that.setData({

tempSavePath: res.tempFilePath

});

}

})

});

解决了