How to apply antialiasing in HTML5 canvas drawImage()?


For antialiasing, you need to set resampling quality.

ctx.imageSmoothingQuality = "low|medium|high"

Use an off-screen canvas to reduce the image to half −

var c = document.createElement('canvas'),
ocx = c.getContext('2d');
c.width = img.width * 0.5;
c.height = img.height * 0.5;

ocxx.drawImage(img, 0, 0, c.width, c.height);

// drawing images reducing to half again and repeating it

ocx.drawImage(c, 0, 0, c.width * 0.5, cc.height * 0.5);

Updated on: 24-Jun-2020

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements