canvas中将y轴方向反转的一种方法
先将原点移动到左下,然后利用坐标缩放,缩放y轴倍数为-1
context.translate(0, canvas.height);
context.scale(1, -1);
注意如果画的是文本,会颠倒。
解决canvas的画线时的锯齿感以及如何让canvas的图更清晰
let width = canvas.width,height=canvas.height;
if (window.devicePixelRatio) {
canvas.style.width = width + "px";
canvas.style.height = height + "px";
canvas.height = height * window.devicePixelRatio;
canvas.width = width * window.devicePixelRatio;
ctx.scale(window.devicePixelRatio, window.devicePixelRatio);
}
来解决Retina屏下的canvas锯齿问题。
网友评论