public class ImgUtil {
public void img_change(String url,String name)
{
Tosmallerpic(url,new File(url+name),"_middle",name,160,160,(float)1);
Tosmallerpic(url,new File(url+name),"_small",name,45,45,(float)0.7);
Tosmallerpic(url,new File(url+name),"_smaller",name,116,100,(float)0.7);
}
/**
*
* @param f 图片所在的文件夹路径
* @param filelist 图片路径
* @param ext 扩展名
* @param n 图片名
* @param w 目标宽
* @param h 目标高
* @param per 百分比
*/
public static void Tosmallerpic(String f,File filelist,String ext,String n,int w,int h,float per){
Image src;
try {
src = javax.imageio.ImageIO.read(filelist); //构造Image对象
String img_midname=f+n.substring(0,n.indexOf("."))+ext+".jpg";
BufferedImage tag = new BufferedImage(w,h,BufferedImage.TYPE_INT_RGB);
//tag.getGraphics().drawImage(src,0,0,new_w,new_h,null); //绘制缩小后的图
tag.getGraphics().drawImage(src.getScaledInstance(w, h, Image.SCALE_SMOOTH), 0,0,null);
ImageIO.write(tag, "jpg", new File(img_midname));
} catch (IOException ex) {
ex.printStackTrace();
}
}
public static void mainX(String args[]){
//String n="0e5465fc-025a-458d-8383-e9ced0c1e728.jpg";
/* String f="C:\\upload\\img\\";
File file=new File(f);
if(file.exists())
{
File[] filelist=file.listFiles();
for(int i=0;i {
String n=filelist[i].getName();
Tosmallerpic(f,filelist[i],"_middle",n,160,160,(float)0.7);
}
} */
//toSmallerPic("d:\\123.png", "d:\\123_111.jpg", 320, 170, Positions.TOP_CENTER, 0.8);
}
}