- 希望在调用onShareAppMessage方法之前通过canvas对图片绘制,生成自定义的分享图片
- 如何在分享之前对图片进行绘制?
相关代码:
wxml:
<button open-type=‘share’ bindtap=‘myShare’ >分享</button>
<canvas canvas-id=‘c’ style=‘width:750px;height:400px’></canvas>
js:
onReady: function () {
var that = this;
ctx.drawImage(’/images/test.jpg’, 0, 0, 750, 400);
ctx.setFillStyle(‘red’);
ctx.setFontSize(30)
ctx.fillText(‘hello’, 30, 30);
ctx.draw(true, setTimeout(() => {
wx.canvasToTempFilePath({
x: 0,
y: 0,
width: 750,
height: 400,
destWidth: 750,
destHeight: 400,
canvasId: ‘c’,
success(res) {
// console.log(res.tempFilePath);
that.setData({
img: res.tempFilePath
})
console.log(that.data.img)
}
})
}, 100))
},
onShareAppMessage: function () {
console.log(this.data.img)
return {
title: ‘这是title’,
imageUrl: this.data.img
}
}
我在onReady里面先绘制好自定义的图片可以实现,但是怎么才能在点击分享按钮时 实现呢?