代码之家  ›  专栏  ›  技术社区  ›  Kenzo_Gilead

使用ionic或angular9在Base64中编码/调整海量图像大小

  •  -1
  • Kenzo_Gilead  · 技术社区  · 5 年前

    ,因此我需要对其进行编码或调整大小。我完全迷路了。。。可能吗?到目前为止,我的代码是:

    base64 = 'data:image/jpeg;base64, ';
    defaultAvatar = './assets/img/resources/img-avatar.png';
    
    if (this.staffService.getStaff() === null) {
          this.staffService.staffInfo().subscribe(data => {
            this.staffData = this.staffService.mapStaffData(data);
            this.avatar_imagen = this.staffData.image ?
              this.domSanitizer.bypassSecurityTrustResourceUrl(
                this.base64 + this.staffData.image
              )
              : this.defaultAvatar;
          });
        } else {
          this.staffData = this.staffService.getStaff();
          this.avatar_imagen = this.staffData.image ?
            this.domSanitizer.bypassSecurityTrustResourceUrl(
              this.base64 + this.staffData.image
            )
            : this.defaultAvatar;
        }
    

    使用的语言必须是 离子的 有棱角的 . (不使用 Javascript )

    1 回复  |  直到 5 年前
        1
  •  1
  •   StepUp    5 年前

    试着使用 ng2-img-cropper 上载前调整图像大小。此外,还可以自定义尺寸标注。

    您可以安装名为的包 ng2 img裁剪机 :

    npm install ng2-img-cropper --save
    

    You can read more about ng2-img-cropper here

    如果你想避免额外的软件包,那么 you can use this TypeScript version of image resizing.

    此外 there is a little bit simplier example . 但是,您还需要创建画布,并且可以使用 ViewChild

    推荐文章