收藏
回答

自定义分享图片的问题

框架类型 问题类型 终端类型 微信版本 基础库版本
小程序 需求 工具 6.5.3 2.3.0

- 希望在调用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里面先绘制好自定义的图片可以实现,但是怎么才能在点击分享按钮时 实现呢?

回答关注问题邀请回答
收藏

3 个回答

登录 后发表内容