class ImagePanel2a extends JPanel
{
/**
* 图像面板类
*/
....................................
String st = "水印";
BufferedImage image = null;
public void paintComponent(Graphics g)
{
super.paintComponent(g);
Graphics2D g2 = (Graphics2D) g;
if (image != null)
{
g2.drawImage(image, 0, 0, this);
g2.setColor(Color.green);//设置水印颜色
g2.drawString(st, 10, 10);//绘制水印,具体水印绘制方式根据自己的需求修改
}
.........
}
.................
}
/**
*保存添加水印后的图片
*
*/
......
BufferedImage bi = new BufferedImage(ImagePanel2a.getWidth(), ImagePanel2a.getHeight(), BufferedImage.TYPE_INT_ARGB);
Graphics2D g2d = bi.createGraphics();
ImagePanel2a.paint(g2d);
ImageIO.write(bi, "PNG", new File("路径"));
....