wx.canvasGetImageData 无法多次调用
发布于 6 年前 作者 juan90 1303 次浏览 来自 问答

  描述: 对画布截图, 当图片太大分成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);

              }

            });

      }

    }

2 回复

遇到同样的问题

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

回到顶部