ImageIO encode split page with original params?

Hey all,

I'm working with TIFF's and the ImageIO library. I split out a single page from a TIFF and then re-encode it, but I can not figure out how to re-encode with the exact same configuration of the original TIFF (i.e. compression, resolution, white/black, etc.).

Is there some way to do this please? Attached is my working code if this helps!

-D

/******

Iterator writers = javax.imageio.ImageIO.getImageWritersByFormatName("tiff");

javax.imageio.ImageWriter writer = (javax.imageio.ImageWriter)writers.next();

ByteArrayOutputStream out = new ByteArrayOutputStream();

javax.imageio.stream.ImageOutputStream ios = javax.imageio.ImageIO.createImageOutputStream(out);

ImageReadParam rparam = imageReader.getDefaultReadParam();

TIFFImageWriteParam writeParam = (TIFFImageWriteParam)writer.getDefaultWriteParam();

writer.setOutput(ios);

writer.write(iiometadata,iioimage,writeParam);

ios.flush();

return out.toByteArray();

*****/

[1040 byte] By [binarymonk01] at [2007-9-30 3:45:33]
# 1
did you get a reply to this question? i am interested in the same problem.
not_my_real_name at 2007-6-29 14:56:39 > top of Java-index,Security,Cryptography...
# 2

I'd be interested to know if you manged to get this to work as well. I'm splitting the pages of a multi-page TIFF to separate TIFFs and need to retain the resolution (i.e. dpi) in the split images as they were in the original. Right now the original is 200 dpi x 200 dpi but the split images come out as 1 dpi x 1 dpi.

mhartman at 2007-6-29 14:56:39 > top of Java-index,Security,Cryptography...
# 3

I'll answer my own question. Key is to copy and/or edit the Node object representing the image's metadata. This is an XML representation of the TIFF tags.

In this example, all the input images properties are encoding in the output image.

ImageReader reader ...

ImageWriter writer ...

...

BufferedImage bi = reader.read(0);

IIOMetadata metaData = reader.getImageMetadata(0);

Node node = metaData.getAsTree("com_sun_media_imageio_plugins_tiff_image_1.0");

ImageOutputStream ios = ImageIO.createImageOutputStream(target);

writer.setOutput(ios);

IIOMetadata imageMetadata = writer.getDefaultImageMetadata(null, writeParam);

imageMetadata.setFromTree("com_sun_media_imageio_plugins_tiff_image_1.0", node);

IIOImage img = new IIOImage(bi, null, imageMetadata);

writer.write(null, img, writeParam);

mhartman at 2007-6-29 14:56:39 > top of Java-index,Security,Cryptography...