一直报这个错:anvasToTempFilePath: fail canvas is empty
< view class = "Canvas_box" wx:if = "{{canvasHidden}}" >
< canvas class = "Canvas" canvas-id = "myCanvas" />
< view class = "save" catch:tap = "handSaveImg" >保存图片</ view >
</ view >
|
createNewImg() {
var that = this
var context = wx.createCanvasContext( 'myCanvas' )
context.setFillStyle( '#fff' )
context.fillRect(0, 0, 375, 667)
var path = '/images/bannerbj.png'
console.log(path)
context.drawImage(path, 0, 0, 340, 550)
context.setFontSize(14)
context.setFillStyle( '#333333' )
context.setTextAlign( 'center' )
let name = this .data.name
context.fillText(name, 175, 235)
context.stroke()
context.setFontSize(50)
context.setFillStyle( '#333333' )
context.setTextAlign( 'center' )
let score = this .data.score
context.fillText(score, 162, 180)
context.stroke()
context.draw( false , e => {
wx.canvasToTempFilePath(
{
canvasId: 'myCanvas' ,
quality: 1,
success: res => {
this .setData({
canvasTemImg: res.tempFilePath,
canvasHidden: true
})
},
fail: res => {
console.log(res)
}
},
this
)
})
},
saveCanvasToFile() {
let that = this
setTimeout(() => {
console.log( '123123123' )
wx.canvasToTempFilePath(
{
canvasId: 'myCanvas' ,
quality: 1,
success: res => {
this .setData({
canvasTemImg: res.tempFilePath,
canvasHidden: true
})
},
fail: res => {
console.log(res)
}
},
this
)
}, 2000)
},
|
没有专门的人员来解答吗?!
请问一下传了this也还是报错,有解决方法吗
使用这个真的痛苦啊,这个就是垃圾玩意,老子废了你们。this死了,
这个功能在写我现在也遇到这个需求但是报错
你的canvas都不存在,怎么绘制
wx:if='{{canvasHidden}}'这里的canvasHidden一开始是false吧
canvasCtx.draw(
false,
wx.canvasToTempFilePath({
canvasId: canvasId,
success: (ctx) => {
console.error('save', ctx);
// 获得图片临时路径,用来保存到本地
},
}),
);