首页 > 文章列表 > 如何在HTML5 canvas的drawImage()函数中应用抗锯齿?

如何在HTML5 canvas的drawImage()函数中应用抗锯齿?

390 2023-09-12

对于抗锯齿,您需要设置重采样质量。

ctx.imageSmoothingQuality = "low|medium|high"

使用离屏画布将图像缩小一半 -

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);

// 绘制图像再次缩小一半并重复

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