图片加水印

public static void main(String[] args) throws IOException { BufferedImage src=ImageIO.read(new File("a.jpg")); //原图 BufferedImage wa=ImageIO.read(new File("b.png")); //水印 int width = src.getWidth(); int height = src.getHeight(); //根据源图片尺寸,产生目标图片 BufferedImage img = new BufferedImage(width, height,BufferedImage.TYPE_INT_RGB); //获取Graphics2D Graphics2D g2 = img.createGraphics(); //绘制源图 g2.drawImage(src, 0, 0, width, height, null); //在已经绘制的图片中加入透明度通道,透明度0~1间 g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, 0.5f)); //绘制水印 g2.drawImage(wa, 0, 0, wa.getWidth(), wa.getHeight(), null); //释放对象 g2.dispose(); //保存文件 ImageIO.write(img, "jpeg", new File("test.jpg")); }

水印重复添加会,逐次降低透明效果。

 

参考:Learning Java 2D

http://java.sun.com/developer/technicalArticles/GUI/java2d/java2dpart1.html

 

你可能感兴趣的:(java,String,File,null)