sree
sree

Reputation: 11

Decoding of old style JPEG-in-TIFF data is not supported

I need to display the 3rd page of scanned tiff files. i used the code

TIFFReader reader = new TIFFReader(new File(pathOfFile));    
RenderedImage image = reader.getPage(2);    

its sometimes work. and show error : Decoding of old style JPEG-in-TIFF data is not supported. I used aspriseTIFF.jar

then how i solve this problem. please reply. thanks in advance

Upvotes: 1

Views: 5883

Answers (1)

Harald K
Harald K

Reputation: 27113

The problem you have run into is that "old style" JPEG compression in the TIFF format (compression == 6), is not supported in the library you use.

This is quite common I guess, as "old-style" JPEG compression is deprecated in TIFF, because it was never fully specified. And because of this under-specification, various vendors implemented it in different, incompatible ways. Support was dropped in favor for TIFF compression 7, JPEG.

Unfortunately, old TIFF files using this compression still exists, so you need to find another library. The good news is that you can use ImageIO and a proper plug-in.

Using a TIFF ImageReader plug-in, like the one from my TwelveMonkeys ImageIO open source project, you should be able to do this:

// Create input stream
try (ImageInputStream input = ImageIO.createImageInputStream(file)) {
    // Get the reader
    ImageReader reader = ImageIO.getImageReaders(input).next();

    try {
        reader.setInput(input);

        // Read page 2 of the TIFF file
        BufferedImage image = reader.read(2, null);
    }
    finally {
        reader.dispose();
    }
}

(sorry about the try/finally boiler-plate, but it is important to avoid resource/memory leaks).

Upvotes: 4

Related Questions