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)文章
SpringBoot中MybatisX插件的簡(jiǎn)單使用教程(圖文)
MybatisX 是一款基于 IDEA 的快速開(kāi)發(fā)插件,方便在使用mybatis以及mybatis-plus開(kāi)始時(shí)簡(jiǎn)化繁瑣的重復(fù)操作,本文主要介紹了SpringBoot中MybatisX插件的簡(jiǎn)單使用教程,感興趣的可以了解一下2023-06-06Java基于IDEA實(shí)現(xiàn)http編程的示例代碼
這篇文章主要介紹了Java基于IDEA實(shí)現(xiàn)http編程的示例代碼,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2021-04-04java Socket編程實(shí)現(xiàn)I/O多路復(fù)用的示例
本文主要介紹了java Socket編程實(shí)現(xiàn)I/O多路復(fù)用的示例,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2023-09-09Spring兩種任務(wù)調(diào)度Scheduled和Async的區(qū)別和應(yīng)用場(chǎng)景詳解
在現(xiàn)代應(yīng)用程序中,任務(wù)調(diào)度是一個(gè)非常普遍的需求,Spring框架提供了兩種主要的方式來(lái)實(shí)現(xiàn)任務(wù)調(diào)度:??Scheduled?? 和 ??Async??,在這篇文章中,我們將詳細(xì)介紹這兩種方式的區(qū)別和應(yīng)用場(chǎng)景,需要的朋友可以參考下2024-12-12Java NumberFormat 類的詳解及實(shí)例
這篇文章主要介紹了Java NumberFormat 類的詳解及實(shí)例的相關(guān)資料,數(shù)字格式化類按照本地風(fēng)格習(xí)慣進(jìn)行的數(shù)字顯示,需要的朋友可以參考下2017-08-08Spring實(shí)現(xiàn)HikariCP連接池的示例代碼
在SpringBoot 2.0中,我們使用默認(rèn)連接池是HikariCP,本文講一下HikariCP的具體使用,具有一定的參考價(jià)值,感興趣的可以了解一下2021-08-08