java 图片加水印实例代码
更新时间:2013年06月20日 10:21:11 作者:
java 图片加水印实例代码,需要的朋友可以参考一下
复制代码 代码如下:
try {
String targetImg = "D:/Blue hills.jpg";
// String pressImg = "D:/20130311220300.jpg";
String pressImg = "D:/html_original.jpg";
File f1 = new File(targetImg);
Image src = ImageIO.read(f1);
int width = src.getWidth(null);
int height = src.getHeight(null);
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
Graphics g = image.createGraphics();
g.drawImage(src, 0, 0, width, height, null);
File f2 = new File(pressImg);
Image src_pao = ImageIO.read(f2);
int width_pao = src_pao.getWidth(null);
int height_pao = src_pao.getHeight(null);
g.drawImage(src_pao, (width-+width_pao)/2, (height-height_pao)/2,width_pao,height_pao, null);
// g.drawImage(src_pao, 100, 100,width,height, null);
g.dispose();
FileOutputStream out = new FileOutputStream(targetImg);
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
encoder.encode(image);
out.close();
System.out.println("水印添加成功!!");
} catch (Exception e) {
// TODO: handle exception
System.out.println("水印添加失败!!");
e.printStackTrace();
}
相关文章
Java中java.lang.ClassCastException异常原因及解决方法
大家好,本篇文章主要讲的是Java中java.lang.ClassCastException异常原因及解决方法,感兴趣的同学赶快来看一看吧,对你有帮助的话记得收藏一下2022-01-01
springboot整合mybatis的超详细过程(配置模式+注解模式)
这篇文章主要介绍了springboot整合mybatis的详细过程(配置模式+注解模式),这里我使用的是配置模式+注解模式所以需要配置全局文件,本文通过实例代码给大家介绍的非常详细,需要的朋友可以参考下2022-04-04
SpringBoot读取properties或者application.yml配置文件中的数据
这篇文章主要介绍了SpringBoot读取properties或者application.yml配置文件中的数据,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧2020-06-06


最新评论