1.一行代码教你用java代码写出图片水印
![在这里插入图片描述](https://img-blog.csdnimg.cn/a0a9fbb2772f4885a631eb4c7a25b9b0.png#pic_center)
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.效果展示
![在这里插入图片描述](https://img-blog.csdnimg.cn/45f82f02c6044ba09e1b027432cf4b0d.png#pic_center)