How to apply antialiasing in HTML5 canvas drawImage()?

HTMLJavascriptProgramming Scripts

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);
raja
Published on 20-Mar-2018 12:15:49
Advertisements