//解决锯齿
var width = canvas.width,height=canvas.height;
if (window.devicePixelRatio) {
devicePixelRatio = window.devicePixelRatio;
canvas.style.width = width + "px";
canvas.style.height = height + "px";
canvas.height = height * devicePixelRatio;
canvas.width = width * devicePixelRatio;
ctx.scale(devicePixelRatio, devicePixelRatio);
}

本文介绍了一种利用设备像素比调整canvas尺寸的方法,有效解决了在不同分辨率下canvas绘图出现的锯齿问题,通过缩放上下文,确保了在高分辨率屏幕上也能绘制出清晰平滑的图像。

1004

被折叠的 条评论
为什么被折叠?



