Ionic framework 在Ionic中调整base64编码图像的大小

Ionic framework 在Ionic中调整base64编码图像的大小,ionic-framework,Ionic Framework,如何在Ionic框架中调整base64编码图像的大小 我想在上传到服务器之前调整客户端的图像大小 在这种情况下,最好的策略是什么?我使用library解决了这个问题: 这个答案可以帮助你:@Ivaro18谢谢,我会查一查 uploadDesktopFile() { let file = this.documentEl.nativeElement.files[0]; const maxHeight = 800; const maxWidth = 600; let

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

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

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

我使用library解决了这个问题:


这个答案可以帮助你:@Ivaro18谢谢,我会查一查
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);
      }
    );
  }