收藏
回答

canvasToTempFilePath无法显示照片,是否是调试基础库的问题?

在使用camera拍照后调用draw和canvasToTempFilePath后回调里面可以看到有照片,但是显示在页面上的时候image为空白

开发者工具使用camera拍照后拿到的照片无法显示,真机可以显示

调试基础库为2.12.2

代码片段如下:

_this.ctx.takePhoto({
      quality: 'high',
      success: (res) => {
        let tempImagePath = res.tempImagePath;
        let cas = wx.createCanvasContext('canvas-' + _this.data.type,this);
        let picWidth = _this.data.width - 2 * _this.data.gap[_this.data.type],
          picHeight = _this.data.width - 2 * _this.data.gap[_this.data.type],
          x,
          y;
        if (_this.data.type != 'peo') {
          x = _this.data.gap[_this.data.type] * 0.625;
          y = _this.data.gap[_this.data.type] * 0.625;
          picWidth = picWidth * 1.59 * 0.625;
          picHeight = picHeight * 0.625;
          cas.scale(0.6250.625);
          cas.translate(0, _this.data.width);
          cas.rotate((270 * Math.PI) / 180);
          cas.drawImage(tempImagePath,0,0,_this.data.width,_this.data.height);
        } else {
          x = 0;
          y = 70;
          cas.drawImage(
            tempImagePath,
            0,
            0,
            _this.data.width,
            _this.data.height
          );
        }
        cas.draw(false, 
          () => {
            console.log('draw done')
            setTimeout(() => {
              wx.canvasToTempFilePath({
                canvasId: 'canvas-' + _this.data.type,
                x: x,
                y: y,
                width: picWidth,
                height: picHeight,
                destWidth: picWidth * 3,
                destHeight: picHeight * 3,
                success: (result) => {
                  console.log('toTempFile done',result)
                  let tempPath = result.tempFilePath,
                    img = 'imgList.' + _this.data.type;
                  if (_this.data.type != 'peo') {
                    _this.ocrIden(_this.data.type, tempPath);
                  } else {
                    _this.setData({
                      showPoup: false,
                      [img]: tempPath,
                    });
                    wx.hideLoading({});
                  }
                  if (
                    _this.data.imgList.peo &&
                    _this.data.imgList.idcardFront &&
                    _this.data.imgList.idcardBack
                  ) {
                    _this.setData({
                      disabled: false,
                    });
                  }
                },
                fail: (res) => {
                  console.log('fail');
                },
              })
            },1000)
          }
        );
      },
      fail: (err) => {
        console.log(err);
      },
    });
回答关注问题邀请回答
收藏

3 个回答

  • Cjiang
    Cjiang
    2020-09-14

    你好,请具体描述问题出现的流程,并提供能复现问题的简单代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html)。

    2020-09-14
    有用
    回复
  • 陈宇明
    陈宇明
    2020-09-14

    你切换下其他基础库试试

    2020-09-14
    有用
    回复
  • 目
    2020-09-14

    takePhoto拿到的照片和canvas.drawImage都可以在页面上显示照片,但是canvasToTempFilePath拿到的照片显示为空

    2020-09-14
    有用
    回复
登录 后发表内容
问题标签