好的,这是我们的问题:

我们正在尝试使用imageio将一系列黑白.tiff文件转换为jpeg2000 .jpf文件。我们总是会看到.jpf文件,但它们通常没有指定的图层数或缩放比例。

这是我们的代码:

 //Get the tiff reader
 Iterator<ImageReader> readerIterator = ImageIO.getImageReadersByFormatName("tiff");
 ImageReader tiffreader = readerIterator.next();

 //make an ImageInputStream from our tiff file and have the tiff reader read it
 ImageInputStream iis = ImageIO.createImageInputStream(itemFile);

 tiffreader.setInput(iis);

 //just pass empty params to the tiff reader
 ImageReadParam tparam;
 tparam = new TIFFImageReadParam();

 IIOImage img = tiffreader.readAll(0, tparam);


 //set up target file
 File f = new File(itemTargetDirectory.getAbsolutePath() + "/" + destFileName);

 //we have tried FILTER_97 as well as different ProgressionTypes and compression settings
 J2KImageWriteParam param;
 param = new J2KImageWriteParam();
 param.setProgressionType("layer");
 param.setFilter(J2KImageWriteParam.FILTER_53);
 //Our problem is that this param is not always respected in the resulting .jpf
 param.setNumDecompositionLevels(5);

 //get the JPEG 2000 writer
 Iterator<ImageWriter> writerIterator = ImageIO.getImageWritersByFormatName("JPEG 2000");
 J2KImageWriter jp2kwriter = null;
 jp2kwriter = (J2KImageWriter) writerIterator.next();

 //write the jpf file
 ImageOutputStream ios = ImageIO.createImageOutputStream(f);
 jp2kwriter.setOutput(ios);
 jp2kwriter.write(null, img, param);


这是一个奇怪的经历,因为同一代码在后续运行中的行为有所不同。
任何见解将不胜感激!

最佳答案

是否所有TIFF文件都具有相同的设置(颜色模型)? J2KImageWriter.java显示当索引颜色或多像素打包的源图像用作输入时,分解级别被设置(强制)为零。

09-10 02:17