使用 Graphics2D 绘制时矩形的实际边界
当使用 Graphics2D 渲染矩形时,如何可靠地确定矩形的准确范围?
假设我有一个起始于 (20,40) 且宽 200 像素、高 100 像素的矩形:
drawRect (20,40,200,100);
当这是一个用 1 像素笔粗略绘制的简单矩形时,我的问题的答案很简单。但是,当画笔为 2 像素、3 像素或更大时,渲染过程中受影响的确切边界是多少?当使用抗锯齿功能时,矩形会“溢出”到相邻像素吗?
计算将被操纵的精确边界的最可靠方法是什么?
How can I reliably determine the exact extent of a rectangle when it is rendered using Graphics2D?
Suppose I have a rectangle that originates at (20,40) and is 200 pixels wide and 100 pixels tall:
drawRect (20,40,200,100);
The answer to my question is easy when this is a simple rectangle, drawn crudely with a 1-pixel pen. However, what are the exact bounds that are affected in the rendering process when the pen is 2 pixels, 3 pixels, or more? And will the rectangle "spill over" to adjacent pixels when anti-aliasing is used?
What is the most reliable way to calculate the exact bounds that will be manipulated?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您需要知道描边形状的边界,您可以自己描边并检查边界。
If you need to know the bounds of a stroked shape, you can stroke it yourself and check the bounds.