java图片等比缩放
package common;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import javax.imageio.ImageIO;
public class ImageCompressionTask implements Runnable{
private InputStream is;
private String fileName;
private int width;
private int height;
/**
* 初始化参数
* @param is 图片输入流
* @param file 图片
* @param fileName 图片名称
* @param width 高
* @param height 宽
*/
public ImageCompressionTask(InputStream is,String fileName,int width,int height) {
this.is=is;
this.fileName=fileName;
this.width=width;
this.height=height;
}
public void run() {
// TODO Auto-generated method stub
try{
this.compressPic();
}catch(Exception e){
System.out.println("文件压缩失败"+e);
}
}
private String compressPic() throws Exception{
String path = "E:\\xie\\";//新图片存放路径
String urlPath = path + fileName;
BufferedImage buffImage;
FileOutputStream output=null;
BufferedImage compressPic=null;
try {
String imagetype = "&#