如何在JAVA中将两个或多个tiff图像文件合并到一个多页tiff图像中 [英] How to combine two or many tiff image files in to one multipage tiff image in JAVA

查看:273
本文介绍了如何在JAVA中将两个或多个tiff图像文件合并到一个多页tiff图像中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有5个单页的tiff图像。
我想将所有这5个tiff图像合并到一个多页tiff图像中。
我正在使用Java Advanced Imaging API。
我已阅读SUN提供的JAI API文档和教程。
我是JAI的新手。我知道基本的核心java。
我不明白SUN的那些文档和文化。
所以朋友请告诉我如何将5个tiff图像文件合并到一个多页tiff图像中。
请给我一些关于上述主题的指导。
我一直在网上寻找上述主题,但没有得到任何一个线索。
所以请指导我的朋友。

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.

提前致谢。

推荐答案

我希望你有计算机内存来做这件事。 TIFF图像文件很大。

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

你是正确的,因为你需要使用 Java Advanced Imaging(JAI) API可以做到这一点。

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

首先,您必须将TIFF图像转换为 java.awt.image.BufferedImage 。这里有一些可能有用的代码。我还没有测试过这段代码。

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, null, OpImage.OP_IO_BOUND);
    image[i] = op.getAsBufferedImage();
}

然后,将BufferedImage数组转换回多个TIFF图像。我还没有测试过这段代码。

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.listIterator(1)); // this may need a check to avoid IndexOutOfBoundsException when vector is empty
encoder.encode(image[0]); 
out.close(); 

祝你好运。

这篇关于如何在JAVA中将两个或多个tiff图像文件合并到一个多页tiff图像中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆