为什么我得到的图片大小是0字节
import java.io.*;
import java.awt.Image;
import javax.imageio.ImageIO;
import java.awt.image.AffineTransformOp;
import java.awt.image.BufferedImage;
import java.awt.geom.AffineTransform;
public class FileOperate {
public FileOperate() {
}
public static String getImageSize(String filePath,int width,int height)
throws Exception{
double Ratio=1.0;
File F = new File(filePath);
if (!F.isFile())
throw new Exception(F+" is not image file error in CreateThumbnail!");
File ThF = new File(filePath.substring(0,filePath.lastIndexOf("/")+1),filePath.substring(filePath.lastIndexOf("/")+1)+"_"+width);
BufferedImage Bi = ImageIO.read(F);
Image Itemp = Bi.getScaledInstance (width,height,Bi.SCALE_SMOOTH);
if ((Bi.getHeight()>height) || (Bi.getWidth()>width)){
double a = width;
double b = height;
double c = Bi.getHeight();
double d = Bi.getWidth();
if (a != 0 && b != 0 && (c/b)>(d/a))
Ratio = b/c;
else
Ratio = a/d;
}
AffineTransformOp op = new AffineTransformOp(AffineTransform.getScaleInstance(Ratio, Ratio), null);
Itemp = op.filter(Bi, null);
try {
ImageIO.write((BufferedImage)Itemp, filePath.substring(filePath.lastIndexOf("/")+1), ThF);
}catch (Exception ex) {
throw new Exception(" ImageIo.write error in CreatThum.: "+ex.getMessage());
}
return (filePath + "_" + width);
}
public static void main(String[] args){
try{
String str = getImageSize("d:/cache/test.jpg",100,100);
System.out.println(str);
}catch(Exception e){
e.printStackTrace();
}
}
}