Skip to main content

Java ImageIO Read and Write compressed Tiff files with CIE lab colorspace

Please note these forums are being decommissioned and use the new and improved forums at
No replies
Joined: 2014-07-14


I'm new here and I'm not sure if this is the correct forum for this, but maybe someone could help.

I actually try to read and write compressed tif-files with CIE Lab colorspace.
Unfortunally if I try to just read and after this write the tif back to the HDD the color is different from the soure tif.
Is the ImageIO lib able to read and write compressed tif files with CIE lab color space?
Interesting is that both (GIMP and Photoshop) says that the source and the result image are both lab 8 bit images, but the
result is much brighter than the source, very confusing.

If it is possible to process such files with the imageIO lib I fear there is something wrong with my code?

Would be great if someone could help me. Thanks a lot!


public class TiffWriter
public static void main(String[] args) throws IOException, SaveErrorException
ArrayList list = new ArrayList<>();
File testTiff = new File("C:/temp/PA993862_hgb.tif");
ImageInputStream iis = ImageIO.createImageInputStream(testTiff);

Iterator readerIterator = ImageIO.getImageReadersByFormatName("tiff");
TIFFImageReader imageReader = (TIFFImageReader);

TIFFImageReadParam tiffReadParam = new TIFFImageReadParam();
BufferedImage source =, tiffReadParam);
IIOMetadata imageMetadata = imageReader.getImageMetadata(0);

File output = new File("C:/Temp/output.tif");

mergeTIFFs(list, output, imageMetadata);

// Done writing all images for this image

public static void mergeTIFFs(List singleTiffs, File newMultiPageTIFF, IIOMetadata imageMetadata) throws IOException
Iterator writers = ImageIO.getImageWritersByFormatName("tiff");
TIFFImageWriter writer = (TIFFImageWriter);
ImageOutputStream ios = ImageIO.createImageOutputStream(newMultiPageTIFF);

// Write each image out to the new file
boolean firstImage = true;
for(int i = 0; i < singleTiffs.size(); i++)
BufferedImage bi = singleTiffs.get(i);
IIOImage image = new IIOImage(bi, null, imageMetadata);
TIFFImageWriteParam tiffWriteParam = new TIFFImageWriteParam(Locale.US);
writer.write(imageMetadata, image, tiffWriteParam);
firstImage = false;
TIFFImageWriteParam tiffWriteParam = new TIFFImageWriteParam(Locale.US);
writer.writeInsert(i, image, tiffWriteParam);
// End writing of all files