1

我实际上尝试使用 CIE Lab 颜色空间读取和写入压缩的 tif 文件。

不幸的是,如果我尝试仅读取并在此之后将 tif 写回 HDD,则颜色与原始 tif 不同。

ImageIO lib 是否能够读取和写入具有 CIE 实验室色彩空间的压缩 tif 文件?

如果可能的话,我担心代码有问题。在 singleTiffs 列表中至少有一个 tiff-ImageInputStream 以这种方式创建: ImageIO.createImageInputStream(testTiff)

如果有人可以帮助我,那就太好了。非常感谢!

// Get iterator for input images
    Iterator<ImageInputStream> iterator = singleTiffs.iterator();

    // Get tif writer and set output to file
    Iterator writers = ImageIO.getImageWritersByFormatName("tiff");
    ImageWriter writer = (ImageWriter) writers.next();
    ImageOutputStream ios = ImageIO.createImageOutputStream(newMultiPageTIFF);
    writer.setOutput(ios);

    // Write each image out to the new file
    boolean firstImage = true;
    while(iterator.hasNext())
    {

        ImageInputStream iis = iterator.next();

        // Get a reader for the stream
        Iterator readers = ImageIO.getImageReaders(iis);
        ImageReader reader = (ImageReader) readers.next();
        reader.setInput(iis);


        // Read the stream metadata
        // IIOMetadata streamMetadata = reader.getStreamMetadata();

        // Read the image metadata - we are assuming there is only one image
        // in the tiff
        IIOMetadata imageMetadata = reader.getImageMetadata(0);

        // Set up the writeParam
        TIFFImageWriteParam tiffWriteParam = new TIFFImageWriteParam(Locale.US);
        tiffWriteParam.setCompressionMode(ImageWriteParam.MODE_COPY_FROM_METADATA);

        BufferedImage bi = reader.read(0, null);
        IIOImage image = new IIOImage(bi, null, imageMetadata);
        if(firstImage == false)
            writer.writeInsert(-1, image, tiffWriteParam);
        else
        {
            writer.write(null, image, tiffWriteParam);
            firstImage = false;
        }

        // Done writing all images for this image
        reader.dispose();
    }

    // End writing of all files
    writer.dispose();
4

0 回答 0