Created
February 2, 2018 02:32
-
-
Save YingshanDeng/5adb117a98d04a9d86ad7da26cb1542c to your computer and use it in GitHub Desktop.
hidp-canvas-polyfill
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 hdpiCanvasPolyfill (canvas) { | |
var dpr = Math.max(1, window.devicePixelRatio || 1) | |
var logicalWidth = canvas.width | |
var logicalHeight = canvas.height | |
canvas.width = dpr * logicalWidth | |
canvas.height = dpr * logicalHeight | |
canvas.style.width = `${logicalWidth}px` | |
canvas.style.height = `${logicalHeight}px` | |
var ctx = canvas.getContext('2d'); | |
ctx.scale(dpr, dpr); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment