您可以将 HTML5 Canvas 像素切片多小?
在 Flash 中,像素是使用缇(即像素的二十分之一)计算的。因此,每个位置始终是 0.05 的倍数。我没有在 HTML Canvas 规范中看到这一点,并且无法跟踪 Canvas 上的光标位置。有谁知道它的像素计算的准确性吗?
编辑澄清:
我更多地指的是芝诺悖论也就是说,为了将某物从 A 点移动到 B 点,它必须首先移动到两点之间的中间点。然后又半途而废,无穷无尽。
因此,如果我想在 x 轴上从 0 点移动到 100 处的 0.5:
- 在第 1 帧:50
- 第 2 帧:75
- 第 3 帧:87.5
- 然后:93.75、96.875、98.4375...等等
那么 Canvas 在哪一步执行实际上四舍五入到下一个像素?
In Flash, pixels are calculated using twips, or twentieth of a pixel. Consequently, every position is always in multiples of 0.05. I haven't seen this mentioned in the HTML Canvas spec and am unable to trace the cursor position on Canvas. Does anyone know the accuracy of its pixel calculations?
Edit for clarification:
I'm referring more to Zeno's paradox which says in order to move something from point A to point B, it must first move to a point halfway between the two. And then halfway again, ad infinitum.
So if I want to move on the x axis from point 0 to 100 at 0.5:
- At frame 1: 50
- Frame 2: 75
- Frame 3: 87.5
- Then: 93.75, 96.875, 98.4375... etc.
So at what step does the Canvas actually round-up to the next pixel?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不确定你所说的切片精度是什么意思。
画布上的像素可以绘制到略小于 0.10,之后它们几乎不会产生任何可见的影响。
当然,如果你缩放,你可以绘制0.00125像素的东西,等等。但如果取消缩放,它们将不可见。
http://jsfiddle.net/GvVD9/
(左上角的第一个方块是一个像素)
鼠标的准确性是完全不同的事情,与画布规格没有任何关系。
编辑:
嗯,我们可以证明这一点。我们可以绘制一堆 y 值接近 100 的像素,并查看它们与 y 值 100 绘制的红色像素的比较。
http://jsfiddle.net/GvVD9/46/
每个水平分隔的部分只是使用drawRect命令的一个1×1像素的矩形。
I'm unsure what you mean by accuracy of slicing.
Pixels on the Canvas can be drawn to a little less than 0.10, after which they make barely any visible impact.
Of course, if you scale, you can draw things that are 0.00125 pixels, and so on. But they won't be visible if you unscale.
http://jsfiddle.net/GvVD9/
(That first square block on the top-left is a pixel)
Accuracy of the mouse is an entirely different thing, in no way related to the canvas spec.
EDIT:
Well, we can sorta demonstrate that. We can draw a bunch of pixels with y values approaching 100 and see how they compare to a red pixel drawn with the y value 100.
http://jsfiddle.net/GvVD9/46/
Every single horizontally separated piece is just a single 1 by 1 pixel rect using the drawRect command.