Java.Images

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 = 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<IIOImage> imageList = new ArrayList<IIOImage>();
 
//...Load images to merge into list using ImageIO.read...
 
Iterator<ImageWriter> 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

 
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