[英]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.我从 canvas 上放大到 20 像素的 spritesheet 中绘制了两个像素。 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?我已经看到了这个问题,但这对我没有帮助当使用 drawImage 从平铺表、精灵表或纹理图集绘制多个图像时,如何防止纹理出血? .
.
Here's my spritesheet and the resulting image:这是我的精灵表和生成的图像:
I have to set imageSmoothingEnabled
to false after resizing the canvas.调整 canvas 的大小后,我必须将
imageSmoothingEnabled
设置为 false。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.