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 龔椿深 閱讀(599) 評論(0)  編輯  收藏


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


          網站導航:
           
          主站蜘蛛池模板: 桐城市| 抚顺市| 樟树市| 太湖县| 松江区| 台北县| 韶山市| 保康县| 永登县| 平泉县| 同江市| 色达县| 石渠县| 香格里拉县| 山东省| 旌德县| 加查县| 普定县| 武冈市| 新建县| 奉贤区| 景宁| 留坝县| 北流市| 横峰县| 铅山县| 河北省| 凤庆县| 亳州市| 北票市| 长武县| 福鼎市| 图木舒克市| 西乌珠穆沁旗| 襄汾县| 永州市| 阿图什市| 中江县| 策勒县| 涿州市| 砀山县|