/**
*大图片文件名,生成小图片的文件名,图片宽度,图片高度
*
*/
protected boolean createMinImage(File fromImg, File toImg, int toWidth,
int toHeight) throws Exception {
try {
// fileExtNmae是图片的格式 gif JPG 或png
// String fileExtNmae="";
double wRatio = 0.0;
double hRatio = 0.0;
double iRatio = 0.0;
BufferedImage Bi = ImageIO.read(fromImg);
// 假设图片宽 高 最大为120 120
hRatio = ((double) toHeight) / Bi.getHeight();
wRatio = ((double) toWidth) / Bi.getWidth();
iRatio = wRatio < hRatio ? wRatio : hRatio;
java.awt.Image Itemp = Bi.getScaledInstance(
(int) (toWidth * iRatio), (int) (toHeight * iRatio),
BufferedImage.SCALE_SMOOTH);
AffineTransformOp op = new AffineTransformOp(AffineTransform
.getScaleInstance(iRatio, iRatio), null);
Itemp = op.filter(Bi, null);
ImageIO.write((BufferedImage) Itemp, "jpg", toImg);
} catch (Exception ex) {
return false;
}
return (true);
}