【问题标题】:Resize base64 encoded image in Ionic在 Ionic 中调整 base64 编码图像的大小
【发布时间】:2018-05-25 17:47:22
【问题描述】:

如何在 Ionic 框架中调整 base64 编码图像的大小。

我想在上传到服务器之前在客户端调整图像大小。

在这种情况下最好的策略是什么?

【问题讨论】:

标签: ionic-framework


【解决方案1】:

我使用ng2-img-max 库解决了这个问题:

uploadDesktopFile() {
    let file = this.documentEl.nativeElement.files[0];

    const maxHeight = 800;
    const maxWidth = 600;

    let self = this;
    this.ng2ImgMax.resizeImage(file, maxHeight, maxWidth).subscribe(
      result => {
        let reader = new FileReader();
        reader.readAsDataURL(result);
        reader.onloadend = function () {
          self.imageURI = reader.result;  // we've got resized base64 sequence at this stage
          //self.uploadFile();
        }
        reader.onerror = function (error) {
          console.error('Error: ', error);
        };
      },
      error => {
        console.error('Error: ', error);
      }
    );
  }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-24
    • 2018-12-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多