How do I create an image with rounded corners in Java?

When I draw BufferedImage with rounded corners

BufferedImage image = new BufferedImage(100, 100, BufferedImage.TYPE_INT_RGB);
Graphics2D graphics = image.createGraphics();
graphics.setColor(Color.WHITE);
graphics.fill(new RoundRectangle2D.Float(0, 0, 60, 60, 20, 20));

      

Output Image:

enter image description here

How can I get the image without black cornerns?

+3


source to share


1 answer


Change BufferedImage.TYPE_INT_RGB

to BufferedImage.TYPE_INT_ARGB

to create a transparent image



+4


source







All Articles