java图片切割圆形

@Test
public void test() {
        try {
            // 读取图片
            BufferedImage bi1 = ImageIO.read(new File("g:/free-sheet-share.jpg"));
            BufferedImage bi2 = new BufferedImage(bi1.getWidth(), bi1.getHeight(),
                    BufferedImage.TYPE_INT_RGB);
            Ellipse2D.Double shape = new Ellipse2D.Double(0, 0, bi1.getWidth(), bi1
                    .getHeight());
            Graphics2D g2 = bi2.createGraphics();
            g2.setBackground(Color.WHITE);
            g2.fill(new Rectangle(bi2.getWidth(), bi2.getHeight()));
            g2.setClip(shape);
            //设置抗锯齿
            g2.drawImage(bi1, 0, 0, null);
            g2.dispose();
            ImageIO.write(bi2, "jpg", new File("e:/2.jpg"));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

 

你可能感兴趣的:(java图片切割圆形)