Making round corners of an Image in Java

An image looks better with round corners and luckily can be easily done using java api.
Here is the code :

 public static BufferedImage makeRoundedCorner(BufferedImage image, int r)
        BufferedImage output = new BufferedImage(r, r, 2);
        Graphics2D g2 = output.createGraphics();
        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        g2.fill(new java.awt.geom.Ellipse2D.Double(0.0D, 0.0D, r, r));
        g2.drawImage(image.getScaledInstance(r, r, 4), 0, 0, null);
        return output;

Uday Ogra

Connect with me at and lets have some healthy discussion :)

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *