gpt4 book ai didi

javascript - Canvas 元素在

转载 作者:行者123 更新时间:2023-11-30 17:52:04 25 4
gpt4 key购买 nike

当我在 Canvas 上的 0,0 坐标处放置一个正方形时,左上角被 chop :

var canvas = document.getElementById('c');
var context = canvas.getContext('2d');
context.strokeStyle = 'blue';
context.rect(0, 0, 200, 100);
context.fillStyle = 'yellow';
context.fill();
context.lineWidth = 7;
context.strokeStyle = 'black';
context.stroke();
<canvas id="c" width="500" height="500"></canvas>

这是为什么?

最佳答案

这是因为一半笔划在 rect.fill 内部,另一半笔划在 rect.fill 外部

有点像 css 边框,您必须在调整大小时/定位时考虑到它们。

在 canvas 的情况下,笔触总是半入/半出对象。

关于javascript - Canvas 元素在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18805622/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com