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

119
Visualizações
imageSmoothingEnabled sometimes doesn't work when drawing canvas on canvas

I notice some weird interaction between clearRect, fillRect and drawImage. It's best explained by a demo: https://jsfiddle.net/tf950zpd/13/ Code:

const c1 = document.getElementById("a").getContext("2d");
const c2 = document.getElementById("b").getContext("2d");
c1.imageSmoothingEnabled = false;
c2.imageSmoothingEnabled = false;
c1.fillStyle = "white";
c1.fillRect(0,0,2,2);
c1.fillStyle = "black";
c1.fillRect(0,0,1,1);
c1.fillRect(1,1,1,1);

document.getElementById("b1").onclick = function() {
    c1.fillRect(0,0,1,1);
}
document.getElementById("b2").onclick = function() {
  c2.clearRect(0,0,100,100);
    c2.drawImage(c1.canvas, 0,0,2,2,0,0,100,100);
}

Html:

<div id="banner-message">
<button id="b1">
  draw A
</button>
<button id="b2">
  draw B
</button>
<canvas id="a" width="2" height="2"></canvas>
<canvas id="b" width="100" height="100"></canvas>
</div>

The expectation is that the smoothing is always disabled when I click "draw B".

If you click draw B twice, it has smoothing disabled for the first time, but smoothing enabled for the second time. If you click "draw A", and then "draw B", it works again for once, but still has smoothing enabled for the second time.

My question is why it doesn't work as expected and how do I fix it?

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