开发者

Actual bounds of a rectangle when drawn with Graphics2D

开发者 https://www.devze.com 2023-02-28 11:31 出处:网络
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:

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 manipulate开发者_如何学JAVAd?


If you need to know the bounds of a stroked shape, you can stroke it yourself and check the bounds.

Graphics2D g;
g.getStroke().createStrokedShape(myRect).getBounds();
0

精彩评论

暂无评论...
验证码 换一张
取 消