我需要一个逻辑来重新调整图像大小,使其始终为 320X240 或更小,并且应保持纵横比。
问问题
1835 次
2 回答
0
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.
于 2011-04-29T22:06:11.897 回答
0
看看ImgScalr,Java 库。具有多种转换质量和速度设置,并为您自动缩放。
BufferedImage sourceImage = ImageIO.read(new File(sourceFile));
BufferedImage destImage = Scalr.resize(sourceImage, Scalr.Method.ULTRA_QUALITY, 320, 240, Scalr.OP_ANTIALIAS);
于 2013-01-02T22:36:49.783 回答