0

I draw two pixels from a spritesheet scaled up to 20 pixels on canvas. But the pixels get smoothed and looks blurred. I want crisp pixel perfect scaling with no blur.

This is my code:

let canvas = document.createElement('canvas');

canvas.width = 320;
canvas.height = 180;

canvas.style.width = '1024px';
canvas.style.height = '1024px';

ctx.imageSmoothingEnabled = false;

ctx.drawImage(241, 16, 2, 2, 8, 0, 20, 20);

// stylesheet
canvas {
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

I've seen this question but that didn't help me How Can I Prevent Texture Bleeding When Using drawImage To Draw Multiple Images From A Tile Sheet, Sprite Sheet, Or Texture Atlas?.

Here's my spritesheet and the resulting image:

bleeding

bleeding

eguneys
  • 6,028
  • 7
  • 31
  • 63

1 Answers1

0

I have to set imageSmoothingEnabled to false after resizing the canvas.

eguneys
  • 6,028
  • 7
  • 31
  • 63