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

High DPI (HiDPI) canvas support #44

Open
joedf opened this issue Sep 26, 2021 · 0 comments
Open

High DPI (HiDPI) canvas support #44

joedf opened this issue Sep 26, 2021 · 0 comments

Comments

@joedf
Copy link

joedf commented Sep 26, 2021

Impressive work! However, it looks blurry on a 4k screen. I think this may be related to #14 and could resolve it.
https://www.html5rocks.com/en/tutorials/canvas/hidpi/

I had this issue with software I was working, and this is the simplest solution I ended up using.

this.canvas.width = e.width * window.devicePixelRatio;
this.canvas.height = e.height * window.devicePixelRatio;
this.canvas.getContext("2d").setTransform(window.devicePixelRatio, 0, 0, window.devicePixelRatio, 0, 0);

Essentially, you render it in the canvas at double resolution (using a transform, double the size of the document element) and scale the document element down to the desired size.

Or even easier, you can just include a polyfill like this one:
https://github.com/jondavidjohn/hidpi-canvas-polyfill

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

1 participant