Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug in fromDataURL for high DPI screen devices #153

Closed
siggifv opened this issue Mar 10, 2016 · 4 comments
Closed

Bug in fromDataURL for high DPI screen devices #153

siggifv opened this issue Mar 10, 2016 · 4 comments

Comments

@siggifv
Copy link

siggifv commented Mar 10, 2016

Description

I've found that the method fromDataURL behaves oddly on devices that don't have the pixel ratio 1, e.g. on mobile devices with high DPI.
I'm aware of the clause in the README where handling of high DPI screens is discussed.
However, I'm still able to reproduce an issue using fromDataURL in cases where the canvas is of a fixed size. I believe that this scaling of the image is the reason for this issue.
You can reproduce this issue using this JSFiddle.

Steps to reproduce

  1. Open the JSFiddled linked in the description above on a device that does not have a pixel ratio of 1 and write something on the signature pad.
  2. Click Save.
    1_after_save
  3. Click Edit.
  4. Write some more on the pad.
    2_before_cancel
  5. Click Cancel

Expected outcome

The signature pad should look exactly like it did after step 2.

Actual outcome

The changes on the signature pad are reverted, but the image has been scaled so it looks different from what was on the pad after step 2.
3_after_cancel

@durasj
Copy link

durasj commented Jun 17, 2016

Hi,

I also stumbled upon this issue. This is unexpected behavior. I think we should have a choice whether we want such modifications (so second argument defaulting to previous behavior should be fine). Mainly because something like that is not done automatically anywhere else.

Thanks a lot @siggifv for your investigation, you saved me some time.

Manually populating canvas is the way for now:

var image = new Image();
signaturePad.clear();
image.src = dataURL;
image.onload = function () {
    signatureCanvas = document.querySelector("#signature-pad");
    signatureCanvas.getContext("2d").drawImage(image, 0, 0, width, height);
};
this.signaturePad._isEmpty = false;

@RonB
Copy link

RonB commented Aug 3, 2016

Hi Durasj,
thanks a lot... have been struggling and used your solution in my angular directive.

@djleonskennedy
Copy link

djleonskennedy commented Dec 10, 2017

Hi @durasj Thanks a lot, works perfectly

my example with accessor's writeValue

  writeValue(value: string): void {
    if (!value) {
      this.signaturePad.clear();
      return;
    }
   this.value = value;
   this._drawValueToCanvas();
   this.cdr.markForCheck();
  }

  /** Draw from image according to retina or some devices  */
  _drawValueToCanvas() {
    if (this.canvas != null) {
      const image = new Image();
      this.signaturePad.clear();
      image.src = this.value;
      image.onload = () =>
        this.canvas
          .getContext('2d')
          .drawImage(image, 0, 0, 300, 120);
      this.signaturePad._isEmpty = false;
    }
  }

@UziTech
Copy link
Collaborator

UziTech commented Jun 8, 2021

fixed in #253

@UziTech UziTech closed this as completed Jun 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants