本文介绍了如何调整图像,而无需加载到内存中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想检查的图像的尺寸,并且如果宽度超过给定的阈值,则它的大小下来。当我打开一个6MB的JPEG图像ImageIO.read(),该BufferedImage的分配有关的堆空间45MB。有没有办法做一个直通图像大小调整,而无需加载所有的数据到内存中?我尝试过ImageIO.read()A File对象,认为它会流从磁盘上的数据,但它并不能帮助。

I'd like to check the dimensions of an image, and then size it down if the width exceeds a given threshold. When I load a 6MB JPEG image with ImageIO.read(), the BufferedImage allocates about 45MB of heap space. Is there a way to do a passthrough image resize without loading all the data into memory? I tried passing ImageIO.read() a File object, thinking it would stream the data from disk, but it doesn't help.

推荐答案

查看 im4java 和的。两者都使用一种名为 ImageMagick的的图像处理非常有效的外部工具。 Im4Java调用命令行程序(不工作在独立的进程),以及JMagick通过JNI同一进程中调用它。

Check out im4java and JMagick. Both use an extremely efficient external tool called ImageMagick for image manipulation. Im4Java calls the command-line app (does work in separate process), and JMagick calls it within the same process via JNI.

如果我做简单的图像处理(缩放,缩放,旋转等),我宁愿让ImageMagick的为我做的。这将是更快,更可靠,并且消耗比什么都重要,你会在一段时间类似的量实现更少的内存。

If I'm doing simple image manipulation (resizing, scaling, rotating, etc), I'd much rather let ImageMagick do it for me. It'll be faster, more reliable, and consume less memory than anything you'd implement in a similar amount of time.

希望这有助于!

这篇关于如何调整图像,而无需加载到内存中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 13:39