graphics 切圆背景透明

Posted yang1018

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了graphics 切圆背景透明相关的知识,希望对你有一定的参考价值。

public static void main(String[] args) throws IOException {
      BufferedImage bi1 = ImageIO.read(new File("    "));
        // 根据需要是否使用 BufferedImage.TYPE_INT_ARGB
        int num =0;
        if(bi1.getWidth()>bi1.getHeight()) {
            num = bi1.getHeight();
        }else {
            num = bi1.getWidth();
        }
        BufferedImage image = new BufferedImage(num,num, BufferedImage.TYPE_4BYTE_ABGR);
 
        Graphics2D g2 = image.createGraphics();
        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        Ellipse2D.Double shape = new Ellipse2D.Double(0, 0, num, num);
        g2.setClip(shape);
        // 使用 setRenderingHint 设置抗锯齿
        g2.drawImage(bi1, 0, 0, null);
        g2.dispose();
 
        try {
            ImageIO.write(image, "PNG", new File("    "));
        } catch (IOException e) {
            e.printStackTrace();
        }


    }
            

 

以上是关于graphics 切圆背景透明的主要内容,如果未能解决你的问题,请参考以下文章