I have a large number of frames that should be placed together on a large image (for example, in a mosaic). Required image positions are required.
There are a very large number of images, so loading them into memory is impractical at best.
Based on some other answers here, I was able to override the methods in RenderedImage (specifically getData(rect) ) to load into the appropriate data and return.
This works fine, however the image author always calls getData and requests a row of data. It seems to me that I should be able to modify ImageWriterParam to call individual tiles instead, but when I tried, the write function still calls a single line from getData .
How can I get this to use tiles and call getTile instead.
BufferedOutputStream bos=null; try { bos = new BufferedOutputStream(new FileOutputStream(new File("test2.tiff"))); ImageWriter writer =(ImageWriter) ImageIO.getImageWritersBySuffix("tif").next(); ImageOutputStream ios=null ios = ImageIO.createImageOutputStream(bos); writer.setOutput(ios); ImageWriteParam param = writer.getDefaultWriteParam(); param.setTilingMode(ImageWriteParam.MODE_DEFAULT); RenderedImage mosaic = new MosaicImage(imageFiles[]); writer.write(null,new IIOImage(mosaic,null,null),param); } catch (FileNotFoundException ex) { }
Note. I can use param.setTilingMode(ImageWriteParam.MODE_EXPLICIT); and setTiling(w,h,xoff,yoff);
However, when using writer.write , it still calls getData(rect) in my image and very annoyingly does not call the rectangle of the size specified by w,h . It calls a rectangle of size, which differs by a random amount (perhaps comes from something)
For example, if I use setTiling(100,100,0,0);
one would expect that even if it does not call getTile from the image, the Rectangle passed to getData should be (0,0,100,100), but instead it passes a Rectangle (0,0,96,96) which is not a multiple of the image width or anything else i can think of.
Thanks for any help