尝试生成海报提示
"canvasToTempFilePath:fail executeCanvasMethod failed: Failed to execute 'drawImage' on 'CanvasRenderingContext2D': The image argument is a canvas element with a width or height of 0."
context.draw(false, setTimeout(function(){
wx.canvasToTempFilePath({
x: 0,
y: 0,
width: 2480,
height: 3366,
destWidth: 2480,
destHeight: 3366,
canvasId: 'share',
fileType: 'jpg',
success: function(res) {
that.setData({
shareImgPath: res.tempFilePath
})
if (!res.tempFilePath) {
wx.showModal({
title: '提示',
content: '图片绘制中,请稍后重试',
showCancel: false
})
}
//画板路径保存成功后,调用方法吧图片保存到用户相册
wx.saveImageToPhotosAlbum({
filePath: res.tempFilePath,
//保存成功失败之后,都要隐藏画板,否则影响界面显示。
success: (res) => {
// console.log(res)
wx.hideLoading()
that.setData({
canvasHidden: true
})
wx.showModal({
title: '保存成功',
content: '已保存到相册,快去分享吧~',
showCancel: false
})
},
fail: (err) => {
console.log(err)
wx.hideLoading()
that.setData({
canvasHidden: true
})
}
})
},
fail: (err) => {
console.log(err)
}
})
},300));
canvas默认给个固定的宽高
去掉canvas中的判断显示隐藏canvasHidden,改为定位超出屏幕看不到
canvas不加display:none
<canvas canvas-id="share" style='width:100vw;height: 100vh;margin-top:100rpx;' hidden='{{canvasHidden}}'></canvas>