The problem with fillRoundRect would seem to be wrong

I have a very simple image generator program that simply draws a rounded rectangle on a BufferedImage and then saves the image to a file.

try
{
    BufferedImage image = new BufferedImage(40, 40, BufferedImage.TYPE_INT_ARGB);

    Graphics2D g2 = image.createGraphics();
    g2.setPaint(Color.blue);

    g2.fillRoundRect(0, 0, 39, 39, 6, 6);

    File file = new File("C:\\test.png");

    ImageIO.write(image, "png", file);
}
catch( IOException e )
{
    e.printStackTrace();
}

Everything works as expected when I draw a rectangle using drawRoundRect:

enter image description here

However, when I use fillRoundRect, the rectangle seems to be clipped on the right and bottom sides:

enter image description here

I tried to make BufferedImage bigger and keep the rectangle the same size, but the problem still exists. In addition, no matter what rectangular width and height, width and height of the arc I choose, the 4 corners do not look the same (although the more it gets, the less pronounced it seems).

Is this a common problem, or may I misunderstand the rounded rectangle?

.

,

B.J.

+3
1

?

g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
+7

Source: https://habr.com/ru/post/1789079/


All Articles