canvasToTempFilePath:fail:create bitmap failed
发布于 6 年前 作者 linwei 1502 次浏览 来自 官方Issues
saveImgToLocal() {
      const that = this;
      setTimeout(() => {
        wx.canvasToTempFilePath({
          canvasId: 'k-canvas',
          destWidth: that.canvasWidthInPx,
          destHeight: that.canvasHeightInPx,
          success: function (res) {
            that.getImageInfo(res.tempFilePath);
          },
          fail: function (error) {
            console.error(`canvasToTempFilePath failed, ${JSON.stringify(error)}`);
            that.triggerEvent('imgErr', {
              error: error
            });
  						const { errMsg } = error
  						if(errMsg === 'canvasToTempFilePath:fail:create bitmap failed') {
  							that.errorCount += 1;
  							if (that.errorCount < 3) {
  									that.saveImgToLocal();
  							} else {
  								// 错了这么多遍基本没救了
  								that.$u.toast('手机性能不够,绘制失败')
  							}
  						}
          },
        }, this);
      }, 300);
    }

微信小程序运行这段代码,华为p10 绘制失败,出现 canvasToTempFilePath:fail:create bitmap failed,延迟和重新调用都没用。

各位前端大神有办法吗?

1 回复

可能是图片过大导致的,缩小图片试试

回到顶部