xiaoguozi's Blog
Pay it forword - 我并不觉的自豪,我所尝试的事情都失败了······习惯原本生活的人不容易改变,就算现状很糟,他们也很难改变,在过程中,他们还是放弃了······他们一放弃,大家就都是输家······让爱传出去,很困难,也无法预料,人们需要更细心的观察别人,要随时注意才能保护别人,因为他们未必知道自己要什么·····
package JingJiaGuo;

import javax.imageio.*;
import java.awt.image.*;
import java.io.*;
public class Image{
    
public Image(String path)
    
throws IOException{
        bi
=ImageIO.read(new File(path));
        weight
=bi.getWidth();
        height
=bi.getHeight();
    }

    
public void SaveTo(String path,String formatname,int maxlen,boolean flag)
    
throws FileNotFoundException,IOException{
        
int nw=weight,nh=height;
        
if(flag){
            
if(weight>maxlen){
                nw
=maxlen;
                nh
=height*nw/weight;
                
if(nh>maxlen){
                    nh
=maxlen;
                    nw
=weight*nh/height;
                }

            }

            
if(height>maxlen){
                nh
=maxlen;
                nw
=weight*nh/height;
                
if(nw>maxlen){
                    nw
=maxlen;
                    nh
=height*nw/weight;
                }

            }

        }
else{
            nw
=nh=maxlen;
        }

        
int imagetype=BufferedImage.TYPE_INT_RGB;
        
if(formatname!="jpeg")imagetype=BufferedImage.TYPE_4BYTE_ABGR_PRE;
        
        ByteArrayOutputStream bous
=new ByteArrayOutputStream();
        BufferedImage tmp
=new BufferedImage(nw,nh,imagetype);
        tmp.getGraphics().drawImage(bi,
0,0,nw,nh,null);
        ImageIO.write(tmp,formatname,bous);
        
        FileOutputStream fos
=new FileOutputStream(path);
        fos.write(bous.toByteArray());
        fos.close();
    }

    
public int weight,height;
    
public BufferedImage bi;
}

暂时未支持动态的gif,不过好像有个开源的gif89的一个开源库,里面有支持动态的gif图像处理的,记下学习笔记
posted on 2009-05-13 22:19 小果子 阅读(184) 评论(0)  编辑 收藏 引用 所属分类: 学习笔记

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理