Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why context2d.backingStorePixelRatio deprecated?

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?

like image 648
kzhdev Avatar asked Jun 20 '14 17:06

kzhdev


1 Answers

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 and height 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.

like image 91
Basic Coder Avatar answered Nov 15 '22 20:11

Basic Coder