public
String
getJSpecialSmallJPG(String fullname,int width,int height,String
type)
throws Exception{
File
_file
=
new
File(fullname);
String newsrc = _file.getParent()+type+_file.getName();
FileInputStream is = null ;
ImageInputStream iis =null ;
Iterator readers =
ImageIO.getImageReadersByFormatName("jpg");
is = new FileInputStream(fullname);
ImageReader reader = (ImageReader)readers.next();
iis = ImageIO.createImageInputStream(is);
reader.setInput(iis,true);
ImageReadParam param = reader.getDefaultReadParam();
Image
src
=
javax.imageio.ImageIO.read(_file);
//构造Image对象
int
x=src.getWidth(null);
//原图的宽
//得到源图宽
int
y=src.getHeight(null);
//原图的高
int tempheight=0;
tempheight=(int) (height*x/width);
int width1=0;
int height1=0;
if(tempheight>y){
width1=(int)(width*y/height);
height1=y;
}else{
height1=(int) (x*height/width);
width1=x;
}
Rectangle rect = new Rectangle(0, 0, width1, height1);
param.setSourceRegion(rect);
BufferedImage bi = reader.read(0,param);
ImageIO.write(bi, "jpg", new File(newsrc));
return newsrc;
}