According to Paul Lewis's article, High DPI Canvas: You need to take into account the context.backingStorePixelRatio
to solve blurring issues.
If this property was deprecated, will dart take care of the blur issue on high definition device?
I thought the exact same thing and as far as the Issue Tracker tells:
Yes, so the article was written back when Safari had a backing store ratio of 2. It's always been 1 in Chrome.
As you say the approach for dealing with this is:
canvas.width = width * window.devicePixelRatio;
canvas.height = height * window.devicePixelRatio;
canvas.style.width = width + 'px';
canvas.style.height = height + 'px';
Where
width
andheight
are however you want them (probably window.innerWidth & innerHeight for full viewport shenanigans.)Then you just need to adjust for the fact that you upscaled the canvas with:
ctx.scale(window.devicePixelRatio, window.devicePixelRatio);
So there you have your solution.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With