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


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

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

更新于:2020 年 6 月 24 日

2K+ 次浏览

开启您的 职业生涯

完成课程获得认证

开始
广告
© . All rights reserved.