cstefanache / angular2-img-cropper

Angular 2 Image Cropper
MIT License
364 stars 135 forks source link

cropCanvas not cleared before drawing Cropped image #58

Closed andriesvn01 closed 8 years ago

andriesvn01 commented 8 years ago

cropCanvas in ImageCropper.ts is not cleared before drawing the Cropped image in the getCroppedImage function. It currently redraws new cropped image onto previous Cropped images.

Quick fix that worked for me:

let tempcanvasContext = this.cropCanvas.getContext("2d");
tempcanvasContext.clearRect(0, 0, this.cropCanvas.width, this.cropCanvas.height)
this.drawImageIOSFix(tempcanvasContext, this.srcImage,
            Math.max(Math.round((bounds.left) / this.ratioW - offsetW), 0),
            Math.max(Math.round(bounds.top / this.ratioH - offsetH), 0),
            Math.max(Math.round(bounds.width / this.ratioW), 1), Math.max(Math.round(bounds.height / this.ratioH), 1),
            0, 0, this.cropCanvas.width, this.cropCanvas.height);
antonbarada commented 8 years ago

+1