wx.canvasToTempFilePath不走成功函数
// pages/canvas/canvasText.js Page({ data: { x: 0, y: 0, hidden: true }, onLoad: function (){ const ctx = wx.createCanvasContext( 'myCanvas' ) // Create linear gradient const grd = ctx.createLinearGradient(0, 0, 10, 80) grd.addColorStop(0, 'red' ) grd.addColorStop(1, 'white' ) // Fill with gradient ctx.setFillStyle(grd) ctx.fillRect(10, 10, 150, 80) ctx.draw() wx.canvasToTempFilePath({ x: 10, y: 10, width: 50, height: 50, destWidth: 100, destHeight: 100, canvasId: 'myCanvas' , success: function (res) { console.log( 'res' ,res.tempFilePath) }, fail: function (err){ console.log( 'err' ,err) }, complete: function (data){ console.log( 'data' , data) } }) }, start: function (e) { this .setData({ hidden: false , x: e.touches[0].x, y: e.touches[0].y }) }, move: function (e) { this .setData({ x: e.touches[0].x, y: e.touches[0].y }) }, end: function (e) { this .setData({ hidden: true }) } }) |
打印出来是err:canvas为空,是这种简单的绘图不支持转成图片输出么?求大佬解答
< canvas canvas-id = "myCanvas" style = "margin: 5px; border:1px solid #d3d3d3;" bindtouchstart = "start" bindtouchmove = "move" bindtouchend = "end" /> < view hidden = "{{hidden}}" > Coordinates: ({{x}}, {{y}}) </ view > |