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

断了今生、忘了曾经 提交于 2021-02-10 14:19:27

问题


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


回答1:


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).



来源:https://stackoverflow.com/questions/23653550/decoding-of-old-style-jpeg-in-tiff-data-is-not-supported

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!