1.一行代码教你用java代码写出图片水印

public static void main(String[] args) throws IOException {
File file = new File("D:\\opt\\test.png");
System.out.println("图片名称:" + file.getName());
System.out.println("图片大小:" + file.length() / 1024 + " kb");
BufferedImage image = ImageIO.read(file);
System.out.println("图片宽度:" + image.getWidth() + " px");
System.out.println("图片高度:" + image.getHeight() + " px");
Graphics2D pen = image.createGraphics();
pen.setColor(Color.RED);
pen.setFont(new Font("微软雅黑", Font.ITALIC, 50));
pen.drawString("格兰婚纱出版社出版水印", 8, 950);
File files = new File("D:\\opt\\test2.png");
FileOutputStream fos = new FileOutputStream(files);
ImageIO.write(image, "png", fos);
}
2.效果展示
