如何更改上传图像的尺寸并将更改后的图像转换为base64 url

时间:2019-01-23 08:25:07

标签: angular base64 image-conversion

目前,我设法更改了图像宽度,但无法更改为我提供更改后的图像的base64值。下面是我的代码  this.fileTobeUpload = file.item(0);

var reader = new FileReader();
reader.onloadend = (event: any) => {
  var image = new Image();

  image.src = event.target.result;
  image.onload = () => {
    image.width = 200;
  }
  this.previewImage = event.target.result;
  this.newsItem.image = this.previewImage
}

reader.readAsDataURL(this.fileTobeUpload);

0 个答案:

没有答案