Last active
March 7, 2021 23:51
-
-
Save jrc03c/9de51deacd79adb428e0263843a5f3f6 to your computer and use it in GitHub Desktop.
Create a high-DPI-compatible canvas element
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function createHighDPICanvas(width, height){ | |
let dpi = window.devicePixelRatio || 1 | |
let canvas = document.createElement("canvas") | |
canvas.width = width * dpi | |
canvas.height = height * dpi | |
canvas.style.width = width + "px" | |
canvas.style.height = height + "px" | |
canvas.getContext("2d").scale(dpi, dpi) | |
return canvas | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment