在draw中调用canvasToTempFilePath失败
步骤:
cxtImg.draw( false , that.saveToImg(mycanvasId))
|
saveToImg: function (mycanvasId) {
console.log( "3.callback:mycanvasId:::" ,mycanvasId);
wx.canvasToTempFilePath({
x: 0 ,
y: 0 ,
width: 200 ,
height: 200 ,
destWidth: 200 * 2 ,
destHeight: 200 * 2 ,
canvasId: mycanvasId,
success(res) {
wx.saveImageToPhotosAlbum({
imagePath: res.tempFilePath,
})
console.log( "3.输出画布成功!!!tempFilePath:::" , tempFilePath);
wx.hideToast()
},
fail(res) {
console.log( "3.输出画布失败!!!::" , res);
}
}, this )
},
|
控制台输出
输出画布失败!!!:: {errMsg: "canvasToTempFilePath: fail canvas is empty" }
|
将wx.canvasToTempFilePath直接作为draw的回调函数,原来把它封装了一下,反而调用失败
主要原因是draw的回调没写对,
cxtImg.draw(
false
, that.saveToImg(mycanvasId))
正确写法如下:cxtImg.draw(false, ()=>{ that.saveToImg(mycanvasId) })
麻烦提供能复现问题的代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html)
代码片段:
https://developers.weixin.qq.com/s/LDKrahmL7n9R
代码片段已分享,麻烦帮忙看看,谢谢
https://developers.weixin.qq.com/s/CZOGHhmD7A97建议检查下代码
是不是canvasId的问题?