Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

129
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda