收藏
回答

wx.canvasGetImageData 无法多次调用

问题模块 框架类型 问题类型 API/组件名称 终端类型 微信版本 基础库版本
API和组件 小程序 Bug canvas 工具 6.6.7 2.0.0

  描述: 对画布截图, 当图片太大分成2张截图数据, 当第2次调用canvasGetImageData
, 如任何反应(successfailcomplete 这个3回调都没日志输入) 。 代码如下:   //图形快照

    this.Snapshot=function()

    {

      var self=this;

      var width = this.ChartBorder.GetChartWidth();

      var height = this.ChartBorder.GetChartHeight();

     


      if (width > 400)

      {

          width=400;

         

          wx.canvasGetImageData(

            {

              canvasId: this.ChartBorder.UIElement.ID,

              x: 0,

              y: 0,

              width: width,

              height: height,

              success(res) {

                self.ScreenImageData =

                  {

                    Data: res.data,

                    Info: { X: 0, Y: 0, Width: width, Height: height }

                  };

                console.log("[HQTradeFrame::Snapshot] canvasGetImageData finish. (large image. Page.1)");

                console.log(self.ScreenImageData.Info);

              }

            });

           


          var width2 = self.ChartBorder.GetChartWidth() - width;

          var x = width;


          wx.canvasGetImageData(

            {

              canvasId: self.ChartBorder.UIElement.ID,

              x: x,

              y: 0,

              width: width,

              height: height,

              success(res) {

                self.ScreenImageData2 =

                  {

                    Data: res.data,

                    Info: { X: x, Y: 0, Width: width2, Height: height }

                  };

                console.log("[HQTradeFrame::Snapshot] canvasGetImageData finish. (large image. Page.2)");

                console.log(self.ScreenImageData2.Info);

              },

              fail(res) {

                console.log("[HQTradeFrame::Snapshot] canvasGetImageData finish. (large image. Page.2)");

              },

              complete(res){

                console.log("[HQTradeFrame::Snapshot] canvasGetImageData finish. (large image. Page.2)");

              }

            });

      }

      else

      {

          self.ScreenImageData2 = null;

          wx.canvasGetImageData(

            {

              canvasId: this.ChartBorder.UIElement.ID,

              x: 0,

              y: 0,

              width: width,

              height: height,

              success(res) {

                self.ScreenImageData =

                  {

                    Data: res.data,

                    Info: { X: 0, Y: 0, Width: width, Height: height }

                  };

                console.log("[HQTradeFrame::Snapshot] canvasGetImageData finish. (small image)");

                console.log(self.ScreenImageData.Info);

              }

            });

      }

    }


最后一次编辑于  2018-05-26  (未经腾讯允许,不得转载)
邀请回答
复制链接收藏投诉关注问题回答

2 个回答

  • 疾驰
    疾驰
    2018-06-11

    你可以加个定时器,上一个运行完毕100ms后再运行下一个


    2018-06-11
    赞同
    回复 2
    • 雪影
      雪影
      2018-06-21

      加个定时器感觉好沙比啊。。。不能重复调用,写一个for循环发现只能调用一次

      2018-06-21
      回复
    • 疾驰
      疾驰
      2018-06-21

      额,定时器不就是类似for循环么,只是每次都固定时间后运行,再加上回调判定,相当于把异步函数同步化

      2018-06-21
      回复
  • 雪影
    雪影
    2018-06-21

    遇到同样的问题

    2018-06-21
    赞同
    回复