收藏
回答

打开摄像头拍照过后白屏?

回答关注问题邀请回答
收藏

1 个回答

  • Demons
    Demons
    2023-02-13

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

    2023-02-13
    有用
    回复 1
    • Poem-Jie
      Poem-Jie
      2023-02-13
      takePhotoAction: function() {
        var that = this
        that.data.ctx.takePhoto({
         quality: 'normal', //高质量
         success: (res) => {
         this.loadTempImagePath(res.tempImagePath);
         },
        })
        },
          loadTempImagePath: function(options) {
            var that = this
            that.data.path = options
            console.log();
            wx.getSystemInfo({
             success: function(res) {
             // 矩形的位置
             var image_x = 15;
             var image_y = 120;
             var image_width = that.data.windowWidth - 2 * 15;
             var image_height = 238;
             console.log(that.data.path);
             wx.getImageInfo({
              src: that.data.path,
              success: function(res) {
                console.log(res);
              that.setData({
               isShowImage: true
              })
              console.log(that.data.isShowImage);
              canvas = wx.createCanvasContext("image-canvas")
              //过渡页面中,图片的路径坐标和大小
              canvas.drawImage(that.data.path, 0, 0, that.data.windowWidth, that.data.windowHeight)
              wx.showLoading({
               title: '数据处理中...',
               icon: 'loading',
               duration: 10000
              })
              // 这里有一些很神奇的操作,总结就是MD拍出来的照片规格居然不是统一的过渡页面中,对裁剪框的设定
              canvas.setStrokeStyle('black')
              canvas.strokeRect(image_x, image_y, image_width, image_height)
              canvas.draw()
              setTimeout(function() {
               wx.canvasToTempFilePath({ //裁剪对参数
               canvasId: "image-canvas",
               x: image_x, //画布x轴起点
               y: image_y, //画布y轴起点
               width: image_width, //画布宽度
               height: image_height, //画布高度
               destWidth: image_width, //输出图片宽度
               destHeight: image_height, //输出图片高度
               success: function(res) {
                that.setData({
                image: res.tempFilePath,
                })
                //清除画布上在该矩形区域内的内容。
                // that.canvas.clearRect(0, 0, that.data.width, that.data.height)
                // that.canvas.drawImage(res.tempFilePath, image_x, image_y, image_width, image_height)
                // that.canvas.draw()
                wx.hideLoading()
                console.log(res.tempFilePath);
                  wx.saveImageToPhotosAlbum({
                filePath: res.tempFilePath,
                success(res) {
                  console.log(res)
                  wx.hideLoading();
                  wx.showToast({
                    title: '保存成功',
                  });
                },
                fail() {
                  wx.hideLoading()
                }
              })
                //在此可进行网络请求
                // PublicJS.drivinglicenseUpload(res.tempFilePath, that.uploadFile);
               },
               fail: function(e) {
                wx.hideLoading()
                wx.showToast({
                title: '出错啦...',
                icon: 'loading'
                })
                if (this.data.skipphotoStatus == 1) {
                wx.redirectTo({
                 url: 'addCarInfo/addCarInfo',
                })
                } else {
                wx.navigateBack({
                 delta: 1
                });
                }
               }
               });
              }, 1000);
              }
             })
             }
            })
            },
      2023-02-13
      回复
登录 后发表内容