在高版本的jdk中,暂未找到替换方案
class Test{
/***
* 图片缩放处理
* <pre>
* Some guidelines:
* 0.75 high quality
* 0.5 medium quality
* 0.25 low quality
* </pre>
*
* @param quality 压缩质量 0.0-1.0 setting of desired quality level.
* @param is 源文件路径
* @param os 目标文件路径
* @param width 预期宽度
* @param height 预期高度
* @throws IOException io
*/
public static void scale(InputStream is, OutputStream os, int width, int height, float quality) throws IOException {
Image srcFile = ImageIO.read(is);
BufferedImage tag = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
tag.getGraphics().drawImage(srcFile, 0, 0, width, height, null);
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(os);
JPEGEncodeParam jep = JPEGCodec.getDefaultJPEGEncodeParam(tag);
jep.setQuality(quality, true);
encoder.encode(tag, jep);
}
}
标签:jep,压缩,jdk1.6,param,height,width,tag,quality,图片
From: https://www.cnblogs.com/chenss15060100790/p/18246809