900字范文,内容丰富有趣,生活中的好帮手!
900字范文 > 微信小程序canvas生成图片为空白问题

微信小程序canvas生成图片为空白问题

时间:2022-08-03 17:41:16

相关推荐

微信小程序canvas生成图片为空白问题

项目中用canvas生成图片时都为空白,原因为 wx.canvasToTempFilePath必须写在wx.draw()的回调中才能实现

createImg ( imgPath) {//生成图片const ctx = wx.createCanvasContext('canvasId')ctx.drawImage(imgPath, 0, 0, w, 280)ctx.draw(false,function() {wx.canvasToTempFilePath({ //写在 draw的回调里面才能生成图片x: 0,y: 0,width: 375,height: 280,destWidth: 375, destHeight: 280, canvasId: 'canvasId',success: function (res) {console.log(res.tempFilePath);}})})}

官方wx.canvasToTempFilePath说明:https://developers./miniprogram/dev/api/canvas/wx.canvasToTempFilePath.html

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。