html52.com
我爱小程序-开发者交流社区

图片压缩上传鸿蒙os提交出错,别的系统都可以成功提交

框架类型 问题类型 API/组件名称 终端类型 微信版本 基础库版本
小程序 Bug wx.createCanvasContext 微信安卓客户端 8.0.23 2.24.5

2.24.5
                        2.24.5

网友回复

Wait:
  //压缩图片
  compressImage() {
    let that = this;
    console.log(this.data.isUploadIndex,that.data.imgs)
    let imagePath = that.data.imgs[this.data.isUploadIndex];
    console.log("====================正在压缩第 " + this.data.isUploadIndex + " 张图片")
    console.log("=========压缩前图片路径:" + imagePath)
    //获取图片大小
    wx.getFileInfo({
      filePath: imagePath,
      success(res) {
        console.log("=========压缩前图片大小:", res.size / 1024'kb');
        if (res.size > 1024 * 1024) {
          //需要压缩
          //获取图片信息
          wx.getImageInfo({
            src: imagePath,
            success(imageInfo) {
              var maxSide = Math.max(imageInfo.width, imageInfo.height);
              //画板的宽高默认
              var windowW = that.data.canvas_width;
              var scale = 1;
              if (maxSide > windowW) {
                scale = windowW / maxSide;
              }
              var imageW = Math.floor(imageInfo.width * scale);
              var imageH = Math.floor(imageInfo.height * scale);


              that.setData({
                canvas_height: imageH
              })


              //压缩图片
              console.log("=========开始压缩")
              var ctx = wx.createCanvasContext('photo_canvas');
              ctx.drawImage(imagePath, 00, imageW, imageH)
              ctx.draw(falsefunction () {
                wx.canvasToTempFilePath({
                  canvasId'photo_canvas',
                  fileType"jpg",
                  successfunction (res{
                    console.log("=========压缩后图片路径:" + res.tempFilePath)
                    wx.getFileInfo({
                      filePath: res.tempFilePath,
                      success(res) {
                        console.log("=========压缩后图片大小:" + res.size / 1024 + 'kb');
                      }
                    })
                    that.uploadImage(res.tempFilePath)
                  }
                }, this)
              })
            }
          })
        } else {
          console.log("=========无需压缩")
          that.uploadImage(imagePath)
        }
      }
    })
  },

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

真正的个人免签约支付接口

云免签H5支付