Problem with fillRoundRect seemingly not rendering correctly
I've got a very simple image generator program that just 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 whenever I draw the rectangle using drawRoundRect:
However, when I use fillRoundRect the rectangle appears to be cropped on the right and bottom sides:
I've tried making the BufferedImage itself larger and keeping the rectangle the same size, but the problem still exists. Also, no matter what rectangular width and height or arc width and height I choose, the 4 corners never look the same (though the larger it 开发者_如何学JAVAgets, the less pronounced it seems to be).
Is this a common problem, or am I perhaps misunderstanding the rounded rectangle?
Any help or suggestions would be much appreciated.
Thanks,
B.J.
Have you tried enabling anti-aliasing?
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
精彩评论