github 头像生成 java_Java 如何根据头像地址生成圆形的头像?
11
2018-12-28 19:03:57 +08:00
隨便寫(xiě)了下,ARGB 帶透明效果,輸出 png 圖片也會(huì)比 jpg 大不少,實(shí)時(shí)生成圖片比較耗時(shí)的,訪問(wèn)量大的話要注意
----------------------代碼分割線-------------------------
public static void main(String[] args) throws IOException {
String str = "這里是圖片鏈接";
URL url = new URL(str);
BufferedImage srcImage = ImageIO.read(url);
int width = srcImage.getWidth();
int height = srcImage.getHeight();
BufferedImage dstImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
Graphics2D g2 = dstImage.createGraphics();
TexturePaint texturePaint = new TexturePaint(srcImage, new Rectangle2D.Float(0, 0, width, height));
g2.setPaint(texturePaint);
Ellipse2D.Float ellipse = new Ellipse2D.Float(0, 0, width, height);
// 抗鋸齒
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2.fill(ellipse);
g2.dispose();
// write to file
ImageIO.write(dstImage, "png", new File("portrait.png"));
// to bytes or inputStream 略
}
總結(jié)
以上是生活随笔為你收集整理的github 头像生成 java_Java 如何根据头像地址生成圆形的头像?的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: java自定义键值对_KV键值对数据类型
- 下一篇: java 选中当前,Java开发网 -