悟心

成功不是将来才有的,而是从决定去做的那一刻起,持续累积而成。 上人生的旅途罢。前途很远,也很暗。然而不要怕。不怕的人的面前才有路。

  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  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 艾波 阅读(1517) 评论(0)  编辑  收藏 所属分类: Java

只有注册用户登录后才能发表评论。


网站导航: