Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

116
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!