Storing a large image in java - tutorial

2019-08-31 04:23发布

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 :)

标签: java jai
4条回答
Root(大扎)
2楼-- · 2019-08-31 04:39

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.

查看更多
▲ chillily
3楼-- · 2019-08-31 04:40

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.

查看更多
【Aperson】
4楼-- · 2019-08-31 04:47

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

查看更多
太酷不给撩
5楼-- · 2019-08-31 05:04

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

查看更多
登录 后发表回答