wx.drawImage画出的图片空白
发布于 5 年前 作者 lijing 1065 次浏览 来自 问答

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 回复

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

我找到原因了是因为

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

});

}

})

});

解决了

回到顶部