收藏
回答

canvas 压缩图片问题?

      const ctx = wx.createCanvasContext('CanvasId');

      console.log(this.data.front)//图片临时地址

      wx.getImageInfo({

            src: this.data.front,

            success: (res) => {

                  var ratio = this.data.pixelRatio

                  if (res.width > size) { // 判断图片是否超过300像素

                        // var scale = res.height / res.width

                        this.setData({

                              cWidth:Math.trunc(res.width / ratio),

                              cHeight:Math.trunc(res.height / ratio)

                        })

                        // 画出压缩图片

                        ctx.drawImage(this.data.front, 0, 0, this.data.cWidth, this.data.cHeight);

                        ctx.draw(false,                                    

                              setTimeout(() => {

                                    wx.canvasToTempFilePath({

                                          canvasId: 'CanvasId',

                                          fileType: 'jpg',

                                          quality:1,

                                          success: (res) => {

                                                console.log(res.tempFilePath)

                                                

                                          },

                                          fail: (res) => {

                                                console.log(res)

                                          }

                                    })

                              },300)

                        

                              

                        )

                  

            }

      });

压缩的图片比原来的图片还大,不知道怎么回事

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

2 个回答

  • 你
    2020-07-15

    你好 你可以看下私信吗 我想向你请教个问题

    2020-07-15
    有用
    回复
  • 污昂ᰔᩚ王࿐
    污昂ᰔᩚ王࿐
    2020-06-20

    quality用0-1 1就是全质量 你用0.5试试

    2020-06-20
    有用
    回复 3
登录 后发表内容
问题标签