====== Java.Images ======
**Handling images with JAI, ImageIO, IIOImage, ...**
reading using ImageReader, ImageIO to IIOImage:
// locate a TIFF reader
Iterator tiffReaders = ImageIO.getImageReadersByFormatName("tiff");
if (!tiffReaders.hasNext()) throw new IllegalStateException("No TIFF reader found");
ImageReader tiffReader = tiffReaders.next();
// point it to our image file
ImageInputStream tiffStream = ImageIO.createImageInputStream(imageFile);
tiffReader.setInput(tiffStream);
// subsample the input image
ImageReadParam tiffReadParam = new ImageReadParam();
tiffReadParam.setSourceSubsampling(SUBSAMPLING_FACTOR, SUBSAMPLING_FACTOR, 0, 0);
// read one page from the TIFF image
IIOImage tiffImage = tiffReader.readAll(pageNumber, tiffReadParam);
// write PNG
response.setContentType(OUTPUT_TYPE);
ImageIO.write(tiffImage.getRenderedImage(), "png", response.getOutputStream());
http://forums.java.net/jive/thread.jspa?messageID=214306
writting multi-page TIFF
List imageList = new ArrayList();
//...Load images to merge into list using ImageIO.read...
Iterator writers = ImageIO.getImageWritersByFormatName("tiff");
ImageWriter writer = writers.next();
ImageOutputStream ios = ImageIO.createImageOutputStream(outputFile);
writer.setOutput(ios);
IIOImage firstIioImage = imageList.remove(0);
writer.write(firstIioImage);
int i = 1;
for(IIOImage iioImage : imageList)
{
writer.writeInsert(i++, iioImage, null);
}
http://forums.java.net/jive/message.jspa?messageID=114422