Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

157
Visualizações
image-rendering: pixelated makes pixels inconsistent sizes even when upscaling by integers

I let the user pick an image, I convert the resulting File object to an ImageBitmap using createImageBitmap(), I render that ImageBitmap onto a <canvas> with no scaling applied, then I upscale that canvas using CSS by saying:

canvas{
    transform-origin: top left;
    transform: scale(2);
    image-rendering: pixelated;
}

When I select a .png file containing pixel art where every pixel in the .png is exactly one pixel in the pixel art (this is the image I'm using, for reference), I expect that scaling this .png up by any integer value should create an image where each pixel is consistently square. In this case, going from 1x1 to 2x2.

However for some reason my result looks like this: image depicting issue

Notice how some pixels are rendered 1x1, others 2x2, and some even appear to be 1x2 or 2x1. Why is this happening?

Snippet to further demonstrate issue:

const canvas = document.getElementById("canvas");
const ctx = canvas.getContext("2d");

const img = document.createElement("img");
img.src = "https://oops-studio.com/downloads/demospritesheetforso.png";// I'm confortable using a remote image as the source here since I own this domain and can guarantee that the image will not be removed

img.addEventListener("load", () => {
  canvas.width = img.width;
  canvas.height = img.height;

  ctx.drawImage(img,0,0);
});
body{
  background: black;
}
canvas{
  transform-origin: top left;
  transform: scale(2);
  image-rendering: pixelated;
}
<canvas id="canvas"></canvas>

After some more testing it seems to be an issue with my PC in some way. I tried it in both Opera and Edge (don't have anything else installed) and it was consistently incorrect. I tried it on another machine (in Opera) and it works perfectly.

Any ideas as to why that is?

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda