Reputation: 149
I have a big geotiff files that I try to split into small png images, using Java language, I cannot read all the picture into a BuffredImage, so I just want to read it and save it as 2 png pictures.
My question is How to split this big geotiff to 2 png or jpeg images and save theme on disk?
Upvotes: 0
Views: 934
Reputation: 7956
There's probably no pure-Java solution for splitting very large TIFF files into smaller ones. However, you could use an utility like tiffmakemosaic
from LargeTIFFTools for splitting the images. The utility comes with built-in functionality for converting the split images into JPEG format.
If you need your images as PNGs, you can use e.g. the ImageIO library as suggested in this thread.
Upvotes: 1
Reputation: 1706
Using Java ImageIO you should be able to read only parts of the file into memory. If the TIFF file is tiled you can read individual tiles using ImageReader.readTile(int, int, int). Otherwise you can use ImageReader.read(int, ImageReadParam) with an ImageReadParam that you have called setSourceRegion on.
Support for these features depends on the actual ImageReader implementation. In this case, no ImageReader for geotiff files is supplied with Java ImageIO, so you will need to get it elsewhere. Since geotiff is fully compliant with TIFF 6.0, you can use an ordinary TIFF reader, if you don't need the additional geo data. There is one included in JAI. I also found a full geotiff reader here: GeoTools. I do not know if either of these ImageReaders support reading partial images though.
Upvotes: 1