I am trying to draw a polygon in 1 pixel increments. Since the whole polygon is scaled to 100, I set the line width to 0.01. For some reason, however, the polygon is drawn with a line width on the screen that looks like 100 pixels instead of 1.
I use GeneralPathas a polygon shape. Thin lines are drawn if I use the same approach for drawing shapes Line2D.
g2d.scale(100, 100);
g2d.setStroke(new BasicStroke(0.01f));
g2d.draw(theShape);
New information: If I delete the setStroke line, I get the 2-pixel line correctly, since BasicStroke 0.02f was previously installed on the Graphics2D object.
This is the real setStroke line
g.setStroke(new BasicStroke((float) (1f / getRoot().scaleX)));
source
share