是否有用于生成缩略图的 Java 库?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3450203/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Are there any java library for thumbnails generation?
提问by Roman
采纳答案by jarnbjo
If you split the task "create thumbnail" into three steps, "load image", "scale image" and "save image", you can do it with the standard Java API. You can use the static utility methods in javax.imageio.ImageIOto load and save images and use Image#getScaledInstance(...)to resize the original image. Since the Imageyou get from getScaledInstanceis not a BufferedImage, you have to create a new BufferedImagewith the correct size and paint the scaled image into the new BufferedImagebefore you can use ImageIO to save it.
如果将“创建缩略图”任务拆分为“加载图像”、“缩放图像”和“保存图像”三个步骤,则可以使用标准 Java API 来完成。您可以使用静态实用程序方法javax.imageio.ImageIO来加载和保存图像并用于Image#getScaledInstance(...)调整原始图像的大小。由于Image您获得getScaledInstance的不是 a BufferedImage,因此您必须创建一个BufferedImage具有正确大小的新图像并将缩放后的图像绘制到新图像中,BufferedImage然后才能使用 ImageIO 保存它。
回答by ieugen
Try thumbnailator: http://code.google.com/p/thumbnailator/. All the code you need to add is:
尝试缩略图:http://code.google.com/p/thumbnalator/。您需要添加的所有代码是:
Thumbnails.of(new File("path/to/directory").listFiles())
.size(640, 480)
.outputFormat("jpg")
.toFiles(Rename.PREFIX_DOT_THUMBNAIL);
It's also fast: https://github.com/coobird/thumbnailator/wiki/Comparison
它也很快:https: //github.com/coobird/thumbnailator/wiki/Comparison
Good luck
祝你好运
回答by SomeDoubts
For creating thumbnails using API methodology, Scalr.resize("your arguments") would be the best one. Also thumbanilator is an option where you dont have to waste much time of yours in understanding, just call the respective method and enjoy with your output thumbnail. Performance/Quality wise Scalr is best. Quality wise thumbnailator is ok.
对于使用 API 方法创建缩略图, Scalr.resize("your arguments") 将是最好的方法。此外,thumbanilator 是一个选项,您不必在理解上浪费太多时间,只需调用相应的方法并享受您的输出缩略图。性能/质量明智的 Scalr 是最好的。质量明智的缩略图是好的。
回答by Russ
回答by dierre
I've checked his site and there's no mention of license. That could mean trouble. At least in Italy where I live because if there's no explicit permission you can't use works that are not yours.
我检查了他的网站,没有提到许可证。那可能意味着麻烦。至少在我居住的意大利,因为如果没有明确许可,您就不能使用不属于您的作品。
I would suggest to read this question: Open source Java library to produce webpage thumbnails server-side
我建议阅读这个问题:开源 Java 库以生成网页缩略图服务器端

