没有人知道,所以我将发布我的解决方案......我决定继续使用 Scalr(我没有检查 Thumbnailator 的最新版本,但之前的在大图上失败了)。因此,首先我调用resize
方法,然后,如果新缩略图的大小比给定的更大,我调用crop
方法,通过中心裁剪缩略图。代码如下:
BufferedImage thumbnail = Scalr.resize(sourceFile, Scalr.Method.ULTRA_QUALITY, Scalr.Mode.AUTOMATIC, destinationSize.width, destinationSize.height);
if (thumbnail.getWidth() > destinationSize.width)
thumbnail = Scalr.crop(thumbnail, (thumbnail.getWidth() - destinationSize.width) / 2, 0, destinationSize.width, destinationSize.height);
else if (thumbnail.getHeight() > destinationSize.height)
thumbnail = Scalr.crop(thumbnail, 0, (thumbnail.getHeight() - destinationSize.height) / 2, destinationSize.width, destinationSize.height);
这并不理想,但至少它在生成缩略图后处理“宽”图像