日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

图像处理之添加图像水印

發布時間:2024/1/23 编程问答 44 豆豆
生活随笔 收集整理的這篇文章主要介紹了 图像处理之添加图像水印 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

常用的圖像加水印一般是在原圖上找一個位置將水印圖像置于上方,本質上就是對兩幅圖像的疊加融合。這里提供兩種方式進行圖像加水印,一種是直接將水印圖像疊加在原圖指定位置,一種是將水印通過一定透明度與原圖指定位置像素進行融合。

當然在水印融合的同時需要考慮,指定位置疊加水印圖像時,水印圖像邊界不會超過原圖邊界。另外也可以使用本身帶有透明通道的圖像作為水印圖像,融合之后的圖像可以形成鏤空水印。

測試圖像:

水印圖像:

第一種方式實現:

public BufferedImage waterMarkerWithLocation(BufferedImage srcImage,BufferedImage waterMarker,int x,int y) {int width = srcImage.getWidth();int height = srcImage.getHeight();BufferedImage resultImage = new BufferedImage(width, height, srcImage.getType());for(int i = 0; i < width;i++) {for(int j = 0; j < height;j++) {int rgb = srcImage.getRGB(i, j);if (i > x & i < (waterMarker.getWidth() + x) & j > y & j < (waterMarker.getHeight() + y)) {rgb = waterMarker.getRGB(i - x, j - y);}resultImage.setRGB(i, j, rgb);}}return resultImage;}

效果:

第二種方式實現:

public BufferedImage waterMarkerWithTransparent(BufferedImage srcImage,BufferedImage waterMarker,double transparent,int x,int y) {int width = srcImage.getWidth();int height = srcImage.getHeight();BufferedImage resultImage = new BufferedImage(width, height, srcImage.getType());for(int i = 0; i < width;i++) {for(int j = 0; j < height;j++) {int rgb = srcImage.getRGB(i, j);if (i > x & i < (waterMarker.getWidth() + x) & j > y & j < (waterMarker.getHeight() + y)) {int rgb1 = waterMarker.getRGB(i - x, j - y);double r = (rgb >> 16) & 0xff;double g = (rgb >> 8) & 0xff;double b = rgb & 0xff;double r1 = (rgb1 >> 16) & 0xff;double g1 = (rgb1 >> 8) & 0xff;double b1 = rgb1 & 0xff;r = (1 - transparent) * r + transparent * r1;g = (1 - transparent) * g + transparent * g1;b = (1 - transparent) * b + transparent * b1;rgb = (255 & 0xff) << 24 | (clamp((int)r) & 0xff) << 16 | (clamp((int)g) & 0xff) << 8 | (clamp((int)b) & 0xff);}resultImage.setRGB(i, j, rgb);}}return resultImage;}

測試效果:
當透明度設置為0.5時

透明度0.2時:

?

總結

以上是生活随笔為你收集整理的图像处理之添加图像水印的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。