[英]Resize Image To Fixed Size
我需要一个逻辑来重新调整图像大小,使其始终为 320X240 或更小,并且应保持纵横比。
查看ImgScalr ,java 的库。 具有多种转换质量和速度设置,并为您自动缩放。
BufferedImage sourceImage = ImageIO.read(new File(sourceFile));
BufferedImage destImage = Scalr.resize(sourceImage, Scalr.Method.ULTRA_QUALITY, 320, 240, Scalr.OP_ANTIALIAS);
1) determine which side of the image is the larger one
2) if its width, calc: faktor = 320/width, else faktor = 240/height;
3) downscale the image by size.x *faktor, size.y *faktor.
例子:
给定:图像有 1024x640
1) its wider than high.
2) faktor = 320 / 1024 -> 0.3125
3) 1024 * 0.3125 = 320 (huh!)
640 * 0.3125 = 200.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.