Java BufferedImage Operation circularize(BufferedImage image)

Here you can find the source of circularize(BufferedImage image)

Description

Makes an image circular

License

Open Source License

Parameter

Parameter Description
image The image to make circular

Return

a circular image of the one passed in

Declaration

public static BufferedImage circularize(BufferedImage image) 

Method Source Code

//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;
    }
}

Related

  1. checkIfManyColors(BufferedImage image)
  2. checkImageMatch(BufferedImage img1, String imgName1, BufferedImage img2, String imgName2)
  3. checkImageType(BufferedImage img, String name)
  4. checkRadius(final BufferedImage src, final int x, final int y, final int opaqueLimit, final int radius)
  5. chunk(BufferedImage image)
  6. cleanBinaryImage(BufferedImage image)
  7. compose(BufferedImage image, BufferedImage mask)
  8. composite(BufferedImage bg, BufferedImage fg)
  9. computeBrightnesses(final BufferedImage image)