How to resize an image without loading into memory?

不打扰是莪最后的温柔 提交于 2019-12-04 07:04:35

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.

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.

Hope this helps!

I've used jmagick before with excellent results, however it can be fiddly to get it working in different environments (sticking the jars in the right place, making sure you've got the correct build of imagemagick, etc).

You might want to consider using imgscalr (http://www.thebuzzmedia.com/software/imgscalr-java-image-scaling-library). It's an open source, pure java image manipulation library available under the Apache 2.0 license. Much much (much..) easier to use and faster than that horrendous Java2D stuff.

You can use ImageInfo to check the width and height of the image without loading it into memory. I do not know of a library that will allow you to re-size without loading the image in memory. 45MB is not all that much memory really. Can you just increase your heap size?

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!