收藏
回答

canvasToTempFilePath 的图片分享不显示

框架类型 问题类型 API/组件名称 终端类型 微信版本 基础库版本
小程序 Bug canvasToTempFilePath 客户端 6.7.3 2.4.0





图片是网络图片,在真机上能看到绘出来的图片,分享的时候图片没有显示,是canvasToTempFilePath的图片不支持分享吗?

最后一次编辑于  2018-11-06
回答关注问题邀请回答
收藏

3 个回答

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

    使用wx.canvasGetImageData获取 canvas 区域隐含的像素数据。然后将获取的像素数据通过wx.arrayBufferToBase64 转成base64就可以直接在真机上使用了

    2021-06-09
    有用 1
    回复
  • JR捌
    JR捌
    2018-11-06

    相关白名单配置了

    2018-11-06
    有用
    回复
  • 是小白啊
    是小白啊
    2018-11-06

    相关的域名配置了吗?

    2018-11-06
    有用
    回复 6
    • JR捌
      JR捌
      2018-11-06


      改成这样就可以,但部分组件引用会报{errMsg: "canvasToTempFilePath: fail canvas is empty"}

      2018-11-06
      回复
    • JR捌
      JR捌
      2018-11-06

      目前解决了。

      发现有几个奇怪的点:

      1. onShareAppMessage只能在页面中监听,在组件中监听不到;

      2. canvas放在组件中会报{errMsg: "canvasToTempFilePath: fail canvas is empty"},放在页面中不会


      2018-11-06
      回复
    • 是小白啊
      是小白啊
      2018-11-06回复JR捌

      组件需要传入this

      2018-11-06
      回复
    • Snow.s
      Snow.s
      2018-11-08

      你好,为什么我用canvasToTempFilePath生成图片编辑器里是可以显示图片的,但是手机里测试不现实图片,只显示文字?


      var textX = that.data.textX,

           textY = that.data.textY + that.data.textSize/2;

         ctx.drawImage(that.data.picPath, that.data.upImgX - that.data.imgx, that.data.upImgY - that.data.imgy, that.data.upImgWidth, that.data.upImgHeight);//图片

         ctx.save();

         ctx.translate(textX, textY);//设置画布上的(0,0)位置,也就是旋转的中心点

         ctx.rotate(that.data.textRotate * Math.PI / 180);

         ctx.setFillStyle('#' + that.data.color[that.data.colorUsed]);

         ctx.setFontSize((that.data.textSize / 2) * that.data.screenRatio);

         ctx.fillText(that.data.textCon, 0, 0);

         ctx.restore();


         ctx.draw(false, function (e) {

           setTimeout(function(){

             wx.canvasToTempFilePath({ //生成图片

               canvasId: 'myCanvas',

               success: function (res) {

                 that.setData({

                   imagePath: res.tempFilePath

                 })

                 console.log(res.tempFilePath);

                 wx.navigateTo({

                   url: "/pages/games/singleShare/singleShare?imagePath=" + res.tempFilePath

                 })

               },

               fail: function (res) {

                 console.log(res)

               }

             },this)

           },500)

         });


      2018-11-08
      回复
    • Snow.s
      Snow.s
      2018-11-08回复是小白啊

      你好,为什么我用canvasToTempFilePath生成图片 在编辑器里可以显示图片,用手机测试不显示图片只有文字?我很着急谢谢!


      2018-11-08
      回复
    查看更多(1)
登录 后发表内容