Handling images with JAI, ImageIO, IIOImage, …

reading using ImageReader, ImageIO to IIOImage:

// locate a TIFF reader
Iterator<ImageReader> tiffReaders = ImageIO.getImageReadersByFormatName("tiff");
if (!tiffReaders.hasNext()) throw new IllegalStateException("No TIFF reader found");
ImageReader tiffReader =;
// point it to our image file
ImageInputStream tiffStream = ImageIO.createImageInputStream(imageFile);
// 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
ImageIO.write(tiffImage.getRenderedImage(), "png", response.getOutputStream());

writting multi-page TIFF

List<IIOImage> imageList = new ArrayList<IIOImage>();
//...Load images to merge into list using
Iterator<ImageWriter> writers = ImageIO.getImageWritersByFormatName("tiff");
ImageWriter writer =;
ImageOutputStream ios = ImageIO.createImageOutputStream(outputFile);
IIOImage firstIioImage = imageList.remove(0);
int i = 1;
for(IIOImage iioImage : imageList)
  writer.writeInsert(i++, iioImage, null);

coding/java/images.txt · Last modified: 2008/05/12 09:32 (external edit)
Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki