最近用到Java动态生成背景透明的图片功能,从gif和png中选择了png格式,自动添加链接地址:http://www.my400800.cn 去网站上的图片中。现把搜索结果总结如下:
1. 生成png图片
int width = 400;
int height = 300;
// 创建BufferedImage对象
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
// 获取Graphics2D
Graphics2D g2d = image.createGraphics();
// 画图
g2d.setColor(new Color(255,0,0));
g2d.setStroke(new BasicStroke(1));
g2d.draw
//释放对象
g2d.dispose();
// 保存文件
ImageIO.write(image, "png", new File("c:/test.png"));
int width = 400;
int height = 300;
// 创建BufferedImage对象
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
// 获取Graphics2D
Graphics2D g2d = image.createGraphics();
// 画图
g2d.setCo