round BufferedImage Corners - Java 2D Graphics

Java examples for 2D Graphics:BufferedImage Resize

Description

round BufferedImage Corners

Demo Code


//package com.java2s;

import java.awt.Graphics2D;

import java.awt.geom.RoundRectangle2D;
import java.awt.image.BufferedImage;

public class Main {
    public static BufferedImage roundCorners(BufferedImage src, int radius) {
        int w = src.getWidth();
        int h = src.getHeight();
        int type = BufferedImage.TYPE_INT_ARGB;
        BufferedImage dst = new BufferedImage(w, h, type);
        Graphics2D g2 = dst.createGraphics();
        RoundRectangle2D r2 = new RoundRectangle2D.Double(0, 0, w, h,
                radius, radius);//from www  .  j  a  v a  2  s.  c o m
        g2.setClip(r2);
        g2.drawImage(src, 0, 0, null);
        g2.dispose();
        return dst;
    }
}

Related Tutorials