收藏
回答

自定义分享图片的问题

框架类型 问题类型 终端类型 微信版本 基础库版本
小程序 需求 工具 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 个回答

  • 禾店短剧系统
    禾店短剧系统
    2021-06-08

    实现分享功能(自定义分享时的描述、名称、小图片)

    https://blog.csdn.net/qq_42910468/article/details/108417491

    2021-06-08
    有用 1
    回复
  • こフ|
    こフ|
    2018-10-18

    是的,可以在进入页面的时候就开始绘制canvas并保存到缓存,如果是让用户点击按钮导出,那可以设置一个loading,缓存成功了再显示转发按钮

    2018-10-18
    有用 1
    回复 1
    • 养乐多
      养乐多
      2018-10-19

      感谢回答

      2018-10-19
      回复
  • 卢霄霄
    卢霄霄
    2018-10-17

    不能再点分享的时候去绘制,来不及,不会等你。。

    2018-10-17
    有用
    回复 11
    查看更多(6)
登录 后发表内容