悟心

          成功不是將來才有的,而是從決定去做的那一刻起,持續(xù)累積而成。 上人生的旅途罷。前途很遠,也很暗。然而不要怕。不怕的人的面前才有路。

            BlogJava :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
            93 隨筆 :: 1 文章 :: 103 評論 :: 0 Trackbacks
          1.//pizza   
          2.package com;   
          3.  
          4.import java.io.FileOutputStream;   
          5.  
          6.  
          7.  
          8.public class ToImg {   
          9.    public static void main(String[] args) throws Exception {   
          10.        toSmaillImg("untitled.bmp","thumb.bmp");   
          11.    }   
          12.       
          13.    public static void toSmaillImg(String filePath,String thumbPath) throws Exception{   
          14.        String newurl =thumbPath;   
          15.        java.awt.Image bigJpg = javax.imageio.ImageIO.read(new java.io.File(filePath));   
          16.        float tagsize = 100;   
          17.        int old_w = bigJpg.getWidth(null);   
          18.        int old_h = bigJpg.getHeight(null);      
          19.        int new_w = 0;   
          20.        int new_h = 0;   
          21.        float tempdouble;    
          22.        tempdouble = old_w > old_h ? old_w/tagsize : old_h/tagsize;   
          23.        new_w = Math.round(old_w/tempdouble);   
          24.        new_h = Math.round(old_h/tempdouble);   
          25.        java.awt.image.BufferedImage tag = new java.awt.image.BufferedImage(new_w,new_h,java.awt.image.BufferedImage.TYPE_INT_RGB);   
          26.        tag.getGraphics().drawImage(bigJpg,0,0,new_w,new_h,null);   
          27.        FileOutputStream newimage = new FileOutputStream(newurl);   
          28.        com.sun.image.codec.jpeg.JPEGImageEncoder encoder = com.sun.image.codec.jpeg.JPEGCodec.createJPEGEncoder(newimage);          
          29.        encoder.encode(tag);   
          30.        newimage.close();   
          31.    }   
          32.}  
          posted on 2010-08-29 16:32 艾波 閱讀(1549) 評論(0)  編輯  收藏 所屬分類: Java
          主站蜘蛛池模板: 西平县| 钟祥市| 视频| 崇文区| 万源市| 防城港市| 龙山县| 若羌县| 崇信县| 定襄县| 资兴市| 神木县| 天津市| 于都县| 高唐县| 克拉玛依市| 贵定县| 阿克陶县| 航空| 叶城县| 雅安市| 吴江市| 莲花县| 青海省| 佛山市| 西丰县| 镇宁| 临沭县| 沽源县| 平度市| 宁阳县| 固始县| 紫云| 长丰县| 保山市| 沁水县| 太和县| 长岛县| 芜湖市| 江永县| 山东省|