【发布时间】:2022-01-13 21:42:05
【问题描述】:
每个人。我制作了一个不同大小的画布,并为 moveTo() 和 lineTo() 绘制了一条具有相同值的线,但我得到了不同大小的线。
这是代码。
function testCanvas(height, width){
canvas = document.createElement("canvas");
ctx = canvas.getContext('2d');
canvas.style.display = "inline-block";
canvas.style.border = "1px solid black";
canvas.height = height;
canvas.width = width;
document.getElementById("chartContainer").appendChild(canvas);
}
function drawLine(x1, y1, x2, y2){
ctx.beginPath();
ctx.moveTo(x1,y1);
ctx.lineTo(x2,y2);
ctx.stroke();
}
-
当我去检查元素 > 控制台并调用时:
testCanvas(300,300); drawLine(10,50,110,50);
和
testCanvas(150,150);
drawLine(10,50,110,50);
行的长度不相等。 现在,如果 moveTo 和 lineTo 的输入以像素为单位,这些线的长度是否相同?这里的默认单位是什么?
【问题讨论】:
标签: javascript html5-canvas html-rendering