<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 :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理

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

    Posted on 2007-09-09 13:40 semovy 閱讀(668) 評論(1)  編輯  收藏 所屬分類: JAVA應(yīng)用
    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給圖片加水印,文字水印 [未登錄]  回復(fù)  更多評論   

    2009-03-18 16:19 by lee
    我頂!!!很強悍謝謝
    主站蜘蛛池模板: 亚洲春色在线视频| 四虎成人精品国产永久免费无码| 直接进入免费看黄的网站| 免费a级毛片18以上观看精品| 成人网站免费看黄A站视频| 亚洲av无码国产精品色在线看不卡 | 男人进去女人爽免费视频国产| 亚洲欧洲自拍拍偷午夜色| 午夜国产大片免费观看| 鲁大师在线影院免费观看| 国产亚洲视频在线观看| 亚洲影院在线观看| 免费人成网站在线高清| 青青青免费国产在线视频小草| 人碰人碰人成人免费视频| 精品亚洲国产成人| 亚洲乱码中文字幕综合 | 久久久久亚洲精品影视| 日韩中文无码有码免费视频| 亚洲天然素人无码专区| 免费看美女被靠到爽的视频| 日本免费中文视频| 成人a毛片视频免费看| 亚洲日韩精品国产3区| 久久亚洲私人国产精品vA| 久久久久亚洲av毛片大| A片在线免费观看| 精品久久久久久亚洲综合网| 亚洲日本国产乱码va在线观看| 自拍偷自拍亚洲精品被多人伦好爽| 中文字幕不卡免费视频| 国产精品亚洲精品久久精品| 亚洲图片校园春色| 亚洲成A∨人片在线观看不卡| 亚洲成AⅤ人影院在线观看| 99精品全国免费观看视频| 日韩免费在线视频| 国产在线观看免费av站| 有色视频在线观看免费高清在线直播| 国产午夜亚洲精品国产| 亚洲精品综合久久|