fix blurry canvas on mobile phones

Solutions on MaxInterview for fix blurry canvas on mobile phones by the best coders in the world

showing results for - "fix blurry canvas on mobile phones"
Emilie
09 Jan 2017
1function createCanvas(width, height, set2dTransform = true) {
2  const ratio = Math.ceil(window.devicePixelRatio);
3  const canvas = document.createElement('canvas');
4  canvas.width = width * ratio;
5  canvas.height = height * ratio;
6  canvas.style.width = `${width}px`;
7  canvas.style.height = `${height}px`;
8  if (set2dTransform) {
9    canvas.getContext('2d').setTransform(ratio, 0, 0, ratio, 0, 0);
10  }
11  return canvas;
12}
13
similar questions
queries leading to this page
fix blurry canvas on mobile phones