使用FormData作为png文件发送图像数据

时间:2017-10-23 12:01:49

标签: angular

我使用angular2-img-cropper并以数据网址格式提供裁剪图像我想将其转换为PNG文件并将其发送到服务器:

cropped(bounds: Bounds) {
  // convert this.data.image to a PNG file
  // send it to the server with form data
}

fileChangeListener($event) {
  const image: any = new Image();
  const file: File = $event.target.files[0];
  const myReader: FileReader = new FileReader();
  const that = this;
  myReader.onloadend = function (loadEvent: any) {
    image.src = loadEvent.target.result;
    that.cropper.setImage(image);
  };
  myReader.readAsDataURL(file);
}
<img-cropper #cropper (onCrop)="cropped($event)" [image]="data" [settings]="cropperSettings"></img-cropper>

0 个答案:

没有答案