【发布时间】:2018-05-25 17:47:22
【问题描述】:
如何在 Ionic 框架中调整 base64 编码图像的大小。
我想在上传到服务器之前在客户端调整图像大小。
在这种情况下最好的策略是什么?
【问题讨论】:
-
这个答案可以帮助你:stackoverflow.com/questions/43212240/…
-
@Ivaro18 谢谢,我去看看
标签: ionic-framework
如何在 Ionic 框架中调整 base64 编码图像的大小。
我想在上传到服务器之前在客户端调整图像大小。
在这种情况下最好的策略是什么?
【问题讨论】:
标签: ionic-framework
我使用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);
}
);
}
【讨论】: