java 圖片加水印實(shí)例代碼
更新時(shí)間:2013年06月20日 10:21:11 作者:
java 圖片加水印實(shí)例代碼,需要的朋友可以參考一下
復(fù)制代碼 代碼如下:
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();
}
相關(guān)文章
Mybatis實(shí)現(xiàn)插入數(shù)據(jù)后返回主鍵過程解析
這篇文章主要介紹了Mybatis實(shí)現(xiàn)插入數(shù)據(jù)后返回主鍵過程解析,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-06-06
java編寫簡(jiǎn)單的E-mail發(fā)送端程序
這篇文章主要介紹了使用java語(yǔ)言編寫一個(gè)簡(jiǎn)單的E-mail發(fā)送端程序,感興趣的小伙伴們可以參考一下2016-02-02
Java中java.lang.ClassCastException異常原因及解決方法
大家好,本篇文章主要講的是Java中java.lang.ClassCastException異常原因及解決方法,感興趣的同學(xué)趕快來看一看吧,對(duì)你有幫助的話記得收藏一下2022-01-01
springboot整合mybatis的超詳細(xì)過程(配置模式+注解模式)
這篇文章主要介紹了springboot整合mybatis的詳細(xì)過程(配置模式+注解模式),這里我使用的是配置模式+注解模式所以需要配置全局文件,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),需要的朋友可以參考下2022-04-04
SpringBoot讀取properties或者application.yml配置文件中的數(shù)據(jù)
這篇文章主要介紹了SpringBoot讀取properties或者application.yml配置文件中的數(shù)據(jù),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-06-06

