Here you can find the source of circularize(BufferedImage image)
Parameter | Description |
---|---|
image | The image to make circular |
public static BufferedImage circularize(BufferedImage image)
//package com.java2s; //License from project: Open Source License import java.awt.*; import java.awt.image.BufferedImage; public class Main { /**/*from w ww. j a v a2 s .c o m*/ * Makes an image circular * * @param image The image to make circular * @return a circular image of the one passed in */ public static BufferedImage circularize(BufferedImage image) { // Making image circular BufferedImage out = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_INT_ARGB); Graphics2D graphics = out.createGraphics(); try { graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); graphics.setColor(Color.BLACK); // The color here doesn't really matter graphics.fillOval(0, 0, image.getWidth(), image.getHeight()); graphics.setComposite(AlphaComposite.SrcIn); // Only paint inside the oval from now on graphics.drawImage(image, 0, 0, null); } catch (Exception e) { e.printStackTrace(); return null; } finally { graphics.dispose(); } return out; } }