Burn component to large TIFF image using JAI

I have a large swing component for writing to TIFF. The component is too large to load TIFF into memory, so I need to either create a large BufferedImage that is supported by Disk WritableRaster (as mentioned here ), or use JAI.

JAI seems like the best answer, except for the complete confusion of the project.

Given, can anyone outline the steps for writing my tiling component in tiled TIFF without running out of memory?

Image size can be 10000x700

Ideally, I would create some kind of disk-based image and write parts of the component to it, each record was flushed to disk.

EDIT

I think I can do this with ImageWriter, but I get a NoSuchElementException on call:

ImageWriter imageWriter = ImageIO.getImageWritersByFormatName("tif").next();

I have jai_code.jar and jai_core.jar jars in my classpath, is there anything else I need to do?

EDIT I can create very large TIFFs using JAI, but JAI does not support TIFF compression, so the file is 92 MB in size.

If I install JAI-ImageIO, I can create compressed TIFF using ImageWriter, but only from Raster or BufferedImage, for which I do not have enough memory.

Is there a way to take a two-step approach, use the JAI to create a large TIFF, and then compress the large TIFF without loading it all into memory?

+3
source share
2 answers

tiff (59392x40192px) JAI. : TiledImages.

TiledImage, . TiledImage, . JAI TileCache, , .

TiledImage , "writeTiled" ( OutOfMemory, ):

public void storeImage(TiledImage img, String filepath) {
    TIFFEncodeParam tep = new TIFFEncodeParam();
    //important to avoid OutOfMemory
    tep.setTileSize(256, 256);
    tep.setWriteTiled(true);
    //fast compression
    tep.setCompression(TIFFEncodeParam.COMPRESSION_PACKBITS);
    //write file
    JAI.create("filestore", img, filepath, "TIFF", tep);
}

690mb (), .

32- WinXP, 1280- HeapSpace, Java VM.

TiledImage IndexedColorModel :

//here you create a ColorModel for your Image
ColorModel cm = source.createColorModel();
//then create a compatible SampleModel, with the tilesize
SampleModel sm = cm.createCompatibleSampleModel(tileWidth,tileHeight);

TiledImage image = new TiledImage(0, 0, imageWidth, imageHeight, 0, 0, sm, cm);
+2
+1

All Articles