Java,J2EE,Weblogic,Oracle

          java項目隨筆
          隨筆 - 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 龔椿深 閱讀(597) 評論(0)  編輯  收藏


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


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 中江县| 淮阳县| 达州市| 华容县| 合阳县| 安阳县| 莫力| 句容市| 阿克陶县| 盐城市| 汤阴县| 广东省| 巴青县| 浪卡子县| 长白| 蒙山县| 印江| 包头市| 枣强县| 报价| 遵义县| 天等县| 湖州市| 武威市| 瓮安县| 抚远县| 青海省| 广德县| 正镶白旗| 阜新市| 泾阳县| 红桥区| 安陆市| 定兴县| 田阳县| 石棉县| 龙陵县| 聂拉木县| 金塔县| 宜兰县| 云和县|