我得到一个巨大的图像在 离子所以我需要编码或调整大小。我很迷茫......这可能吗?我的代码到目前为止是。
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)谢谢大家。
试试使用 ng2-img-cropper
来调整图片的大小,然后再上传。此外,您还可以自定义尺寸。
您可以安装名为 ng2-img-cropper
:
npm install ng2-img-cropper --save
您可以在这里阅读更多关于ng2-img-cropper的信息。
如果你想避免额外的包,那么 你可以使用这个TypeScript版本的图像大小调整。
此外。 有一个更简单的例子. 然而,你还需要创建某个地方的画布,你可以使用 ViewChild
来与之合作。