-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
fromDataUrl fails on tablet #89
Comments
After checking, if this can help, the problem doesn't occur on iPad (safari + chrome) |
I don't own a tablet with Android, but hopefully I'll be able check it on my friend's Nexus 5 on Monday. Does it also happen if you draw the image on Nexus 7 and then read it back? |
I also own a nexus 5: it happens too with it. |
@mathpere I still haven't tried it out on Nexus 5, but I prepared some tests, tried it out on non-retina and retina Macbooks and it seems to work fine. Here's the first jsfiddle with image created on non-retina Macbook ( Here's the first jsfiddle with image created on retina Macbook ( I used this jsfiddle to create those images: http://jsfiddle.net/szimek/u4zmsmbL. If you click "Get data" button, it will open a new window where you can copy the data URL from. This HiDPI stuff is pretty confusing, so it's still possible that my tests are somehow messed up and it doesn't work correctly after all. Let me know if it actually helps in any way :) |
Hi, Thanks for your support. I don't know yet how to interpret these tests.
I will probably use intensively signature pad again in the next few days, I will let you know. |
Hi, Finally, I fixed my encountered issue by replacing in the fromDataUrl function these lines:
by these lines:
It seems to work as expected on both Macbook pro non-retina and nexus 7. |
@mathpere Thanks. I'll try it again, because I think the image in the second test looked ok on a non-retina Mac. Could you fork these 2 tests, change the lines you mentioned and post links to them here? I'll try both mine and your versions then. |
Hello, For your information, I meet the same problem as @mathpere on an Android Phone (Android 5.0.2) and his solution works perfectly. Thanks! |
Hello! The image halfing happens on my macbook pro retina. |
If i set the zoom to 50% (which makes the window.devicePixelRation to be 1, it works correctly. |
If I move the window to an external / non-retina window, the behaviour is fixed (since window.dpr == 1) |
Why is the division there in the first place? |
I can confirm the issue for iPhone 5 / iPad Air 2 with mobile Safari (newest iOS) as well as Google Nexus 9 with Android 5.1. The question is, what the ratio scaling was supposed to achieve in the first place: I would suggest drawing the images on the canvas as is and give the user optional variables to change width and height. |
any news on when this is to be fixed? the proposed fix from @mathpere seems to do the trick for me. |
@ben3005 Unfortunately I don't have much time lately and I want to check if the fix doesn't break anything before merging it. I'll try to sort it out by the end of this month. |
@szimek awesome, thanks! :) A little christmas present for us, eh? |
@szimek awesome, thanks for letting us know |
This one is really confusing :/ I created yet another demo (http://jsfiddle.net/szimek/x80q89xd/) which loads an image created on my old non-retina MacBook and the image is displayed correctly on both non-retina ( I created it simply by doing: setTimeout(function () {
console.log(signaturePad.toDataURL());
}, 10000) and then copying data from the console. I'm not sure how it's different from the sample provided by @mathpere and why it works differently. Here's a picture of both laptops displaying the same image on the canvas: |
Looks like it's related to the code responsible for scaling the canvas in the demo app. It's present in my jsfiddle and the image is displayed correctly there. If you remove this code (just comment out the line with |
Somehow I get the feeling that it would be best to internalize the canvas in the library as there are a lot of pit falls from not dealing with the canvas element correctly. Maybe just hook the library to a div container and let the library handle the creation / resize of the canvas. |
@PerfectPixel You may be right, but the problem is that people want to do really strange stuff with it. E.g. instead of For now I guess I'll add a section about handling canvas element to the README file, i.e. the following code with some explanation: function resizeCanvas() {
var ratio = Math.max(window.devicePixelRatio || 1, 1);
canvas.width = canvas.offsetWidth * ratio;
canvas.height = canvas.offsetHeight * ratio;
canvas.getContext("2d").scale(ratio, ratio);
}
window.addEventListener("resize", resizeCanvas);
resizeCanvas(); Maybe this callback function could be added as a configuration option and the code above could be the default. But then some people might want to have some throttling there and I'd have to modify the library again... |
Well in my case the issue is, I changed the scale of the context and then changed the dimensions. Turns out that changing the dimensions after scaling is equivalent to not using I'll adjust the code once I get back to work after new year and get back to you with feedback. |
@PerfectPixel I've added a section about handling high DPI screens to the readme: . It's not much besides what's already in this topic, but it would be awesome if you could read it and let me know if it explains it well and is clear enough. |
@szimek sorry for coming around a little late. I read through the readme, looks good from my perspective. However, I noticed a small pitfall: if you fit your canvas at 100% width or height in the parent container, then you need to scale it down with css. Otherwise your canvas will have 200% implicit width/height on high DPI screens. We are using the canvas in a bootstrap modal, use the modals width as the canvas width and scale the height proportionately. If we do not scale the canvas with css, it flows out over the side of the modal. |
The scaling solution did not work in my scenario. Applying the scaling fixed the image when loaded using .fromDataURL() but the canvas size doubled. Also the point of input was shifted from where the mouse/finger actually made contact on the signature pad. I was able to fix the issue by overriding the .fromDataURL() function and removing the pixelRatio logic.
|
The same happens with toSvg() when created in mobile. it does not seem to get scaled. |
When I've changed browser zoom to 75% the fromDataURL become not working - after each draw action on canvas the extra elements have been added - elements duplicate what I have drawn, but their size was if I would drawn it in zoom 100%. @rwacker solution help me. |
|
I think this was fixed in #253 |
Hi,
I use this awesome lib on my current project and I meet some issue with tablet.
First of all, all is working fine on desktop browser (mac non-retina, chrome / firefox).
The problem occured on tablet (nexus 7, android lollipop, Chrome) with fromDataURL: The signature size is shrank on tablet.
Here is a demo: http://jsbin.com/tixuje/2/edit?html,js,output
If you open this link: http://jsbin.com/tixuje/2 on desktop, you will see this one:
When I open this same link: http://jsbin.com/tixuje/2 on my tablet, I get a shrank signature:
Do you know where does the problem?
The text was updated successfully, but these errors were encountered: