// 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为空,急求大神,微信小程序出问题了,帮我看下~哭哭哭哭哭哭哭哭哭哭 ...。是这种简单的绘图不支持转成图片输出么?求大佬解答