views:

75

answers:

1

Hello Friends!

I have 5 single page tiff images. I want to combine all these 5 tiff images in to one multipage tiff image. I am using Java Advanced Imaging API. I have read the JAI API documentation and tutorials given by SUN. I am new to JAI. I know the basic core java. I dont understand those documentation and turorial by SUN. So friends Please tell me how to combine 5 tiff image file in to one multipage tiff image. Please give me some guidence on above topic. I have been searching internet for above topic but not getting any single clue. So please guide me friends.

Thanks in advance.

+2  A: 

I hope you have the computer memory to do this. TIFF image files are large.

You're correct in that you need to use the Java Advanced Imaging (JAI) API to do this.

First, you have to convert the TIFF images to a java.awt.image.BufferedImage. Here's some code that will probably work. I haven't tested this code.

BufferedImage image[] = new BufferedImage[numImages];
for (int i = 0; i < numImages; i++) {
    SeekableStream ss = new FileSeekableStream(input_dir + file[i]);
    ImageDecoder decoder = ImageCodec.createImageDecoder("tiff", ss, null);
    PlanarImage op = new NullOpImage(decoder.decodeAsRenderedImage(0), 
            null, OpImage.OP_IO_BOUND, null);
    image[i] = op.getAsBufferedImage();
}

Then, you convert the BufferedImage array back into a multiple TIFF image. I haven't tested this code either.

TIFFEncodeParam params = new TIFFEncodeParam();
OutputStream out = new FileOutputStream(output_dir + image_name + ".tif"); 
ImageEncoder encoder = ImageCodec.createImageEncoder("tiff", out, params);
Vector vector = new Vector();   
for (int i = 0; i < numImages; i++) {
    vector.add(image[i]); 
}
params.setExtraImages(vector.iterator()); 
encoder.encode(image[0]); 
out.close(); 

Good luck.

Gilbert Le Blanc
Thank you Sir!for your reply. I will defiantly try your logic.Thank you very much!
Param-Ganak
You're welcome.
Gilbert Le Blanc
Thank You Sir! for your reply and solution. I have implemented your solution and it works perfect. With some changes its working as per my requirement. Thank You Very Much!
Param-Ganak
You're welcome. Now that you know about BufferedImage, you can do other photo transformations.
Gilbert Le Blanc