yzpure 最近的时间轴更新
yzpure

yzpure

V2EX 第 325889 号会员,加入于 2018-06-30 20:11:02 +08:00
yzpure 最近回复了
2018-12-29 14:22:03 +08:00
回复了 codechaser 创建的主题 Java 请教一下为什么我这样 POST 总是会返回 400?
header 和 data 之间少一个空行,把最后 buffW.write("\r\n")上移一行。另外 header 最好加上 Content-Length
2018-12-28 19:03:57 +08:00
回复了 samples 创建的主题 程序员 Java 如何根据头像地址生成圆形的头像?
随便写了下,ARGB 带透明效果,输出 png 图片也会比 jpg 大不少,实时生成图片比较耗时的,访问量大的话要注意
----------------------代码分割线-------------------------
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 略
}
关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5427 人在线   最高记录 6543   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 14ms · UTC 07:38 · PVG 15:38 · LAX 00:38 · JFK 03:38
Developed with CodeLauncher
♥ Do have faith in what you're doing.