Java,J2EE,Weblogic,Oracle

          java項(xiàng)目隨筆
          隨筆 - 90, 文章 - 6, 評論 - 61, 引用 - 0
          數(shù)據(jù)加載中……

          JAVA 大圖片轉(zhuǎn)換為小圖片

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

          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);
             // 假設(shè)圖片寬 高 最大為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)  編輯  收藏


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


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 永康市| 尼玛县| 高邑县| 宜春市| 海丰县| 天全县| 抚顺县| 自贡市| 广灵县| 平遥县| 隆德县| 罗山县| 同心县| 涟水县| 永登县| 思南县| 林西县| 通河县| 北安市| 朝阳区| 浙江省| 正定县| 河西区| 武安市| 宝鸡市| 肥西县| 太原市| 武宣县| 上蔡县| 台北县| 中山市| 互助| 什邡市| 阿城市| 越西县| 西吉县| 蛟河市| 泰安市| 林州市| 宁海县| 罗源县|