Java,J2EE,Weblogic,Oracle

          java項目隨筆
          隨筆 - 90, 文章 - 6, 評論 - 61, 引用 - 0
          數據加載中……

          JAVA 大圖片轉換為小圖片

          /**
          *大圖片文件名,生成小圖片的文件名,圖片寬度,圖片高度
          *
          */

          protected boolean createMinImage(File fromImg, File toImg, int toWidth,
             int toHeight) throws Exception {
            try {
             // fileExtNmae是圖片的格式 gif JPG 或png
             // String fileExtNmae="";
             double wRatio = 0.0;
             double hRatio = 0.0;
             double iRatio = 0.0;

             BufferedImage Bi = ImageIO.read(fromImg);
             // 假設圖片寬 高 最大為120 120

             hRatio = ((double) toHeight) / Bi.getHeight();
             wRatio = ((double) toWidth) / Bi.getWidth();
             iRatio = wRatio < hRatio ? wRatio : hRatio;

             java.awt.Image Itemp = Bi.getScaledInstance(
               (int) (toWidth * iRatio), (int) (toHeight * iRatio),
               BufferedImage.SCALE_SMOOTH);
             AffineTransformOp op = new AffineTransformOp(AffineTransform
               .getScaleInstance(iRatio, iRatio), null);
             Itemp = op.filter(Bi, null);
             ImageIO.write((BufferedImage) Itemp, "jpg", toImg);
            } catch (Exception ex) {
             return false;
            }
            return (true);
           }

          posted on 2009-05-19 15:29 龔椿深 閱讀(597) 評論(0)  編輯  收藏


          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 建德市| 鹤山市| 惠州市| 山阳县| 长寿区| 新密市| 贵州省| 卢湾区| 同仁县| 体育| 永济市| 汶上县| 临邑县| 黄大仙区| 通州区| 疏勒县| 金昌市| 大悟县| 文登市| 满洲里市| 嘉定区| 二手房| 金昌市| 宜昌市| 榆树市| 云龙县| 同江市| 中西区| 翁源县| 酉阳| 新田县| 牙克石市| 浠水县| 凤山市| 横峰县| 林芝县| 呼图壁县| 南涧| 冀州市| 柳河县| 新巴尔虎左旗|