Storing a large image in java - tutorial

痴心易碎 提交于 2019-12-25 07:47:26

问题


I need to save a large image on disk - so large it creates outofmemory errors (like 10000x10000 px). It's suppose to be a tiling and I have the tile stored in memory as a BufferedImage. I read something about TiledImage class being able to work only with part of image, the rest being stored on disk, but I haven't found a simple example of how to do this? Could you please point me to or create a tutorial for dummies on how to store a large image on disk without having it all in memory? Like "create large image straight on disk like this:", "access its part and store data in it like this:" or however it works..

I know this has been asked here a couple of times, but I read through all of that and googled a lot but still haven't found a whole working (or comprehendable) example. Maybe it's the language barrier, or I'm just stupid in this kinda stuff, anyway, help, please :)


回答1:


Have you checked out DiskMemImage, from their documentation:

This class serves the same purpose as JAI's standard TiledImage class: namely, a writable image that can accommodate a variety of data types, an optional ColorModel, and data arranged in tiles. However, unlike TiledImage, DiskMemImage uses disk as well as memory storage to allow very large images to be handled in limited memory.




回答2:


You can give a look to PNGJ, I created that library for a similar scenario.




回答3:


Easy way to solve OutOfMemoryError in java is to increase the maximum heap size by using JVM options




回答4:


I would just increase your maximum memory, it is much simpler. Try it with -Xmx1g on the command line.

There is no magic to using tiles. You just break up your image into smaller images when you stitch together on the screen so it looks like a large one. e.g. Google maps do this.



来源:https://stackoverflow.com/questions/14069418/storing-a-large-image-in-java-tutorial

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