我使用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>