<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
    我頂!!!很強悍謝謝
    主站蜘蛛池模板: 免费毛片毛片网址| 亚洲色大成网站www久久九| 特色特黄a毛片高清免费观看 | 一级大黄美女免费播放| xvideos亚洲永久网址| 99视频免费在线观看| 亚洲狠狠爱综合影院婷婷| 日本一区二区三区在线视频观看免费| 四虎影永久在线高清免费| 欧美激情综合亚洲一二区| 免费一看一级毛片| 国产精品美女免费视频观看| 亚洲精品tv久久久久久久久| 精品视频在线免费观看| 亚洲综合一区二区| 亚洲欧洲免费无码| 国产精品亚洲一区二区三区久久| 日本一道一区二区免费看 | 亚洲日韩中文在线精品第一| 高清免费久久午夜精品| 日韩亚洲欧洲在线com91tv| 久久免费国产精品一区二区| 亚洲日韩乱码中文无码蜜桃| 午夜毛片不卡高清免费| 成年网站免费入口在线观看| 国产亚洲色视频在线| 2020因为爱你带字幕免费观看全集 | 亚洲欧洲日韩极速播放| 国产青草视频免费观看97| 国产精品免费看久久久香蕉| 久久精品国产99精品国产亚洲性色| 麻花传媒剧在线mv免费观看| 亚洲av日韩av永久无码电影| 中文字幕在线亚洲精品| 69免费视频大片| 老湿机一区午夜精品免费福利| 亚洲国产精品久久久久婷婷软件| 精品久久久久国产免费| 一级特黄录像免费播放肥| 亚洲另类古典武侠| 91老湿机福利免费体验|