【发布时间】:2016-07-20 16:28:28
【问题描述】:
我正在编写一个 java 程序来将 tiff 文件转换为单独的图像,但是我无法使用 ImageDecoder,因为我的 tiff 文件不包含 II* 作为开始,然后我的 tiff 文件以一些标题开头图像以 II* 开头。请告知如何删除 tiff 图像中 II* 之前的标题部分。 下面是我用来分隔图像的代码,但是由于 tiff 不是以 II* 开头,我遇到了如下异常
Exception in thread "main" java.lang.IllegalArgumentException: Bad endianness tag (not 0x4949 or 0x4d4d).
以下是我从 tiff 中分离图像的方法。
FileSeekableStream ss = new FileSeekableStream("D:\\Users\\Vinoth\\workspace\\Testing\\Testing.tif");
ImageDecoder dec = ImageCodec.createImageDecoder("tiff", ss, null);
int count = dec.getNumPages();
TIFFEncodeParam param = new TIFFEncodeParam();
param.setLittleEndian(false); // Intel
System.out.println("This TIF has " + count + " image(s)");
for (int i = 0; i < count; i++) {
RenderedImage page = dec.decodeAsRenderedImage(i);
File f = new File("D:\\Users\\Vinoth\\workspace\\Testing\\single_" + i + ".tif");
System.out.println("Saving " + f.getCanonicalPath());
ParameterBlock pb = new ParameterBlock();
pb.addSource(page);
pb.add(f.toString());
pb.add("tiff");
pb.add(param);
RenderedOp r = JAI.create("filestore",pb);
r.dispose();
【问题讨论】:
标签: java inputstream tiff endianness javax.imageio