程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> JAVA編程 >> 關於JAVA >> java 圖片加水印實例代碼

java 圖片加水印實例代碼

編輯:關於JAVA

java 圖片加水印實例代碼。本站提示廣大學習愛好者:(java 圖片加水印實例代碼)文章只能為提供參考,不一定能成為您想要的結果。以下是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();
        }

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved