wx.createSelectorQuery()
.in(this)
.select('#myCanvas')
.fields({ node: true, size: true })
.exec((res) => {
console.log('res' ,res)
this.canvas = res[0].node
this.canvasContext = this.canvas.getContext('2d')
this.canvasWidth = res[0].width
this.canvasHeight = res[0].height
用的是最新的canvas
wx.canvasToTempFilePath({
x: 0,
y: 0,
width: this.canvas.width,
height: this.canvas.height,
// destWidth: 400,
// destHeight: 500,
canvasId: 'myCanvas',
fileType: 'png',
success(res) {
console.log('保存画布成功' ,res)
},
fail(err){
console.log('保存画布失败' ,err)
}
});
保存图片失败,errMsg: "canvasToTempFilePath:fail fail canvas is empty",不知道该如何操作了,API里也没有相关说明,求解?
canvas type="2d" 时需使用 canvas 属性,你没有传这个属性。