gpt4 book ai didi

java - 使用 ImageIO 编写带有图层(即分解级别)的 JPEG 2000

转载 作者:行者123 更新时间:2023-11-30 11:30:15 25 4
gpt4 key购买 nike

好的,这是我们的问题:

我们正在尝试使用 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显示当索引颜色或多像素打包源图像用作输入时分解级别设置(强制)为零。

关于java - 使用 ImageIO 编写带有图层(即分解级别)的 JPEG 2000,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17888575/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com