首页 > java > java清晰的图片缩放

java清晰的图片缩放

2009年2月3日 发表评论 阅读评论

/**
* @param inputFile
* @param outputPicName 文件全名,后缀为.jpg
* @param max
* @author wenc
*/
public static void zoomPicture(File inputFile, String outputPicName,double max) {
double maxLimit = max;
double ratio = 1.0;
try {
BufferedImage Bi = ImageIO.read(inputFile);
if ((Bi.getHeight() > maxLimit) || (Bi.getWidth() > maxLimit)) {
if (Bi.getHeight() > Bi.getWidth())
ratio = maxLimit / Bi.getHeight();
else
ratio = maxLimit / Bi.getWidth();
}
int widthdist=(int)Math.floor(Bi.getWidth() * ratio),
heightdist =(int)Math.floor(Bi.getHeight() * ratio);

BufferedImage tag = new BufferedImage(widthdist, heightdist,
BufferedImage.TYPE_INT_RGB);

tag.getGraphics().drawImage(Bi.getScaledInstance(widthdist, heightdist, BufferedImage.SCALE_SMOOTH), 0, 0, null);

File littleFile = new File(outputPicName);
ImageIO.write(tag, “JPEG”, littleFile);
} catch (Exception ex) {
log.error(“图片写入错误” + ex.getMessage());
}
}

分类: java 标签: 4,458 次阅读
原文链接:http://www.wenhq.com/article/view_240.html
欢迎转载,请注明出处:亲亲宝宝
  1. 本文目前尚无任何评论.
  1. 本文目前尚无任何 trackbacks 和 pingbacks.