.NET 矩形缩小 1
使用 .NET GDI+ 矩形对象后,我注意到如果我创建一个 X:0 * Y:0 * 宽度:100 * 高:100 的矩形,则 Right
和 Bottom
属性设置为 100, 100。这不应该是 99, 99 吗? 0 - 99 是 100 像素。 0 - 100 是 101 像素。
FWIW,文档确实说右侧是通过 x + width 计算的,底部是 y + height 计算的,但这是正确的吗?也许“正确”在这里并不重要,只要它是一致的?
我所知道的是,这有点(读起来……非常)烦人!
After working with the .NET GDI+ Rectangle object, I've noticed that if I create a rectangle that is X:0 * Y:0 * Width:100 * Height:100, the Right
and Bottom
properties are set to 100, 100. Shouldn't this be 99, 99? 0 - 99 is 100 pixels. 0 - 100 is 101 pixels.
FWIW, the documentation does say the right is computed by x + width
and the bottom is y + height
, but is that correct? Perhaps "correct" doesn't matter here as long it's consistent?
All I know is that it is somewhat (read... very) annoying!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
来自文档:
“还描述了客户区的尺寸通过包含区域的客户坐标的 Rectangle 结构 在所有情况下,矩形的左上坐标都包含在客户区域中,而右下坐标不包括右边缘和下边缘。客户区。”
因此,您的 x 点包含集合 [0,100),即 100 个值。
From the documentation:
"The dimensions of the client area are also described by a Rectangle structure that contains client coordinates for the area. In all cases, the upper-left coordinate of the rectangle is included in the client area, while the lower-right coordinate is excluded. Graphics operations do not include the right and lower edges of a client area."
So, your x points comprise the set [0,100) which is 100 values.
这取决于您是否将坐标视为标记整个像素,或标记像素之间的点。如果将它们视为无限小的点,则 (0, 0) 和 (100, 0) 之间的像素数为 100 个像素。但是,如果您将它们视为对像素进行标记 - 使得像素 (0, 0) 和 (100, 0) 都包含在矩形中,那么正如您所说,这显然是 101 像素宽。
当然,如果能在某个地方详细说明这一点就好了。我怀疑是这样,但我还没有看过相关文档。希望有人可以提供链接:)
It depends on whether you regard the coordinates as labelling whole pixels, or labelling points between pixels. If you regard them as infinitely small points, then the number of pixels between (0, 0) and (100, 0) is 100 pixels. If, however, you regard them as labelling the pixels - such that both pixels (0, 0) and (100, 0) are included in the rectangle, then that's clearly 101 pixels wide as you say.
It would be nice to have this spelled out somewhere, of course. I suspect it is, but I haven't run across the relevant documentation. Hopefully someone can provide a link :)