<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    posts - 0, comments - 77, trackbacks - 0, articles - 356
      BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理

    java給圖片加水印,文字水印

    Posted on 2007-09-09 13:40 semovy 閱讀(675) 評論(1)  編輯  收藏 所屬分類: JAVA應用
    public final class ImageUtils ...{
        
    public ImageUtils() ...{

        }

        
        
    public final static String getPressImgPath()...{
            
    return ApplicationContext.getRealPath("/template/data/util/shuiyin.gif");
        }


     
    /** *//**
      * 把圖片印刷到圖片上
      * 
    @param pressImg -- 水印文件
      * 
    @param targetImg  -- 目標文件
      * 
    @param x
      * 
    @param y
      
    */

        
    public final static void pressImage(String pressImg, String targetImg, int x, int y) ...{
            
    try ...{
                File _file 
    = new File(targetImg);
                Image src 
    = ImageIO.read(_file);
                
    int wideth = src.getWidth(null);
                
    int height = src.getHeight(null);
                BufferedImage image 
    = new BufferedImage(wideth, height,
                        BufferedImage.TYPE_INT_RGB);
                Graphics g 
    = image.createGraphics();
                g.drawImage(src, 
    00, wideth, height, null);

                
    // 水印文件
                File _filebiao = new File(pressImg);
                Image src_biao 
    = ImageIO.read(_filebiao);
                
    int wideth_biao = src_biao.getWidth(null);
                
    int height_biao = src_biao.getHeight(null);
                g.drawImage(src_biao, wideth 
    - wideth_biao - x, height - height_biao -y, wideth_biao,
                        height_biao, 
    null);
                
    // /
                g.dispose();
                FileOutputStream out 
    = new FileOutputStream(targetImg);
                JPEGImageEncoder encoder 
    = JPEGCodec.createJPEGEncoder(out);
                encoder.encode(image);
                out.close();
            }
     catch (Exception e) ...{
                e.printStackTrace();
            }

        }


        
    /** *//**
         * 打印文字水印圖片
         * 
    @param pressText --文字
         * 
    @param targetImg -- 目標圖片
         * 
    @param fontName -- 字體名
         * 
    @param fontStyle -- 字體樣式
         * 
    @param color -- 字體顏色
         * 
    @param fontSize -- 字體大小
         * 
    @param x -- 偏移量
         * 
    @param y
         
    */

         
        
    public static void pressText(String pressText, String targetImg, String fontName,int fontStyle, int color, int fontSize, int x, int y) ...{
            
    try ...{
                File _file 
    = new File(targetImg);
                Image src 
    = ImageIO.read(_file);
                
    int wideth = src.getWidth(null);
                
    int height = src.getHeight(null);
                BufferedImage image 
    = new BufferedImage(wideth, height,
                        BufferedImage.TYPE_INT_RGB);
                Graphics g 
    = image.createGraphics();
                g.drawImage(src, 
    00, wideth, height, null);
                
    // String s="www.qhd.com.cn";
                g.setColor(Color.RED);
                g.setFont(
    new Font(fontName, fontStyle, fontSize));
             

                g.drawString(pressText, wideth 
    - fontSize - x, height - fontSize/2 - y);
                g.dispose();
                FileOutputStream out 
    = new FileOutputStream(targetImg);
                JPEGImageEncoder encoder 
    = JPEGCodec.createJPEGEncoder(out);
                encoder.encode(image);
                out.close();
            }
     catch (Exception e) ...{
                System.out.println(e);
            }

        }


        
    public static void main(String[] args) ...{
            pressImage(
    "C:/shuiyin/shuiyin.gif""c:/shuiyin/DSC02342.JPG"20 ,20);
        }

    }
     

    評論

    # re: java給圖片加水印,文字水印 [未登錄]  回復  更多評論   

    2009-03-18 16:19 by lee
    我頂!!!很強悍謝謝
    主站蜘蛛池模板: 91亚洲视频在线观看| 亚洲av无码无线在线观看 | 一级毛片免费视频| 亚洲一区二区三区91| 免费人妻无码不卡中文字幕18禁| 国产在线观看xxxx免费| 亚洲精品影院久久久久久| 精品无码国产污污污免费| 免费无码作爱视频| 亚洲伦理中文字幕| 国产AV无码专区亚洲AV手机麻豆| 中文字幕成人免费视频| 国产精品日本亚洲777| 亚洲一区二区三区高清| 国产免费av一区二区三区| 久久免费视频精品| 337p日本欧洲亚洲大胆人人| 久久精品亚洲综合一品| 国产在线观看免费不卡| 91精品视频在线免费观看| 色五月五月丁香亚洲综合网| 亚洲网站在线观看| 亚洲精品无码你懂的网站| www视频免费看| 亚洲一区二区三区免费| 国产精品亚洲片在线va| 亚洲国产成人精品无码区在线观看| 四虎影院免费在线播放| 日本免费一区二区三区| 一级做a爰片久久免费| 亚洲人成无码网站在线观看| 亚洲色图在线观看| 亚洲乱码中文字幕综合| 国产免费拔擦拔擦8x| 美女被cao免费看在线看网站| 中文字幕不卡免费视频| 看全免费的一级毛片| 亚洲欧美国产欧美色欲| 亚洲精品一区二区三区四区乱码| 亚洲毛片αv无线播放一区| 亚洲精品视频免费|