简体   繁体   中英

draw 2 pixels on canvas scaled to 20 pixels with no blur or texture bleeding

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:

流血的

流血的

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM