收藏
回答

onShareAppMessage使用canvas画图显示不出来

大神们好,想canvas画图作为onShareAppMessage的imageUrl,但是为啥我的显示不出来呢?帮看看啥问题吧,非常感谢


//调用cropImg这个函数由imgSrc图片生成一个新的图片保存在headShare 全局变量中

cropImg: function(imgSrc) {

    wx.getImageInfo({

        src: imgSrc,

        success: function(ret) {

            var orWidth = ret.width

            var orHeight = ret.height

            ctx.drawImage(imgSrc, 0, orHeight * 1 / 10, orWidth, orHeight * 8 / 1000500400);

            ctx.draw(falsefunction() {

            wx.canvasToTempFilePath({

                canvasId: 'attendCanvasId',

                fileType: 'jpg',

                success: function(resl) {

                    wx.saveFile({//把文件保存到本地

                        tempFilePath: resl.tempFilePath,

                        success: function(res) {

                                headShare = res.savedFilePath

                                console.log(headShare)

                            }

                        })

                    }

                }) //wx.canvasToTempFilePath end

            }) //ctx.draw end

        }

    })

},


//调用onShareAppMessage之前已经生成图片文件并保存到headShare变量中

onShareAppMessage: function(res) {

    console.log(headShare)//可以打印出图片本地路径

    return {

        title: xitieInfo.title,

        path: '/pages/showxitie/showxitie',

        imageUrl: headShare,

        success: function(res) {

            console.log('成功', res)

        },

        fail: function(res) {

               // 转发失败

             console.log('失败', res)

        }

    }

},


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

5 个回答

  • 低端人
    低端人
    2018-09-06

    要先wx.downFile之后的才能绘制,而且draw()之后需要一定时间才能去生成临时路径

    2018-09-06
    有用
    回复
  • 金钱豹
    金钱豹
    2018-09-06

    wx.canvasToTempFilePath({})  这个保存的图片不就是在本地吗,你还要在保存一次?

    2018-09-06
    有用
    回复
  • 侯衍超
    侯衍超
    2018-09-06

    真机上能出来吗

    2018-09-06
    有用
    回复
  • haisen
    haisen
    2018-09-04


    2018-09-04
    有用
    回复
  • 卢霄霄
    卢霄霄
    2018-09-04

    cropImg 在哪里调用的呢

    2018-09-04
    有用
    回复 15
    • haisen
      haisen
      2018-09-04

      onLoad里面调用了个wx.request,在request的success里面调用的

      2018-09-04
      回复
    • 卢霄霄
      卢霄霄
      2018-09-04回复haisen

      截个图呢?

      2018-09-04
      回复
    • haisen
      haisen
      2018-09-04回复卢霄霄

      您看一下截图,生成的图片可以显示在页面里,但是点转发就没有显示,console可以打印出本地的图片URL

      2018-09-04
      回复
    • 卢霄霄
      卢霄霄
      2018-09-04回复haisen

      你调用 ctx.draw() 方法的地方,截个图呢

      2018-09-04
      回复
    • haisen
      haisen
      2018-09-04回复卢霄霄


      2018-09-04
      回复
    查看更多(10)
登录 后发表内容