Java – fillroundrect appears to be a problem that cannot be rendered correctly

I have a very simple image generator program. It just draws a rounded rectangle on the buffered image, 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,39,6,6);

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

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

Whenever I use drawroundrect to draw a rectangle, everything works as expected:

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

I've tried to make bufferedimage itself larger and keep the rectangle the same size, but the problem still exists In addition, no matter what rectangle width and height or arc width and height I choose, the four corners look different (although the larger it is, the less obvious it looks)

Is this a common question, or may I misunderstand rounded rectangles?

Any help or advice will be appreciated

thank you,

B.J.

Solution

Have you ever tried to enable anti aliasing?

g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>