Graphics2D 圆角图片
时间: 2023-04-03 08:02:05 浏览: 58
显示圆角图片
可以使用 Graphics2D 绘制圆角图片,具体实现可以参考以下代码:
```
public static BufferedImage makeRoundedCorner(BufferedImage image, int cornerRadius) {
int w = image.getWidth();
int h = image.getHeight();
BufferedImage output = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
Graphics2D g2 = output.createGraphics();
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2.setColor(Color.WHITE);
g2.fill(new RoundRectangle2D.Float(, , w, h, cornerRadius, cornerRadius));
g2.setComposite(AlphaComposite.SrcIn);
g2.drawImage(image, , , null);
g2.dispose();
return output;
}
```
阅读全文