java清晰的图片缩放
/**
* @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());
}
}
欢迎转载,请注明出处:亲亲宝宝