Question

Out-of-the-box ArrayIndexOutOfBoundsException when attempting to use Apache-Commons Sanselan to load a TIFF that was compressed with PackBits compression.

Code:

import org.apache.sanselan.*;

public class TIFFHandler {
    public static Image loadTIFF(String fileName) throws ImageReadException, IOException {
        File imageFile = new File(fileName);
        BufferedImage bi = Sanselan.getBufferedImage(imageFile);
        return bi;
    }

    public static void main(String[] args) throws IOException, ImageReadException {
        String TIFFFILE = "test_image.tif";
        JFrame frame = new JFrame();
        frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        JPanel panel = new JPanel();
        BufferedImage bi = (BufferedImage) loadTIFF(TIFFFILE);
        ImageIcon ii = new ImageIcon(bi);
        JLabel lbl = new JLabel(ii);
        panel.add(lbl);
        frame.setVisible(true);
    }
}

Stack trace:

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 426
at org.apache.sanselan.common.PackBits.decompress(PackBits.java:55)
at org.apache.sanselan.formats.tiff.datareaders.DataReader.decompress(DataReader.java:127)
at org.apache.sanselan.formats.tiff.datareaders.DataReaderStrips.readImageData(DataReaderStrips.java:96)
at org.apache.sanselan.formats.tiff.TiffImageParser.getBufferedImage(TiffImageParser.java:505)
at org.apache.sanselan.formats.tiff.TiffDirectory.getTiffImage(TiffDirectory.java:163)
at org.apache.sanselan.formats.tiff.TiffImageParser.getBufferedImage(TiffImageParser.java:441)
at org.apache.sanselan.Sanselan.getBufferedImage(Sanselan.java:1264)
at org.apache.sanselan.Sanselan.getBufferedImage(Sanselan.java:1255)
at TIFFHandler.loadTIFF(FieldSheetHandler.java:42)
at TIFFHandler.main(FieldSheetHandler.java:90)

I've attempted an analysis of the problem, but I'm pretty lost...any directions would be really helpful. TIFF images are a pain in the a**.

Was it helpful?

Solution

You can try the updated version of Commons Imaging from the Apache snapshot repository. The Javadoc is not online yet, you'll have to build it by checking out the code from SVN and running mvn javadoc:javadoc.

If you find more issues or want to suggest an improvement you can file them in JIRA. Also the developers will be happy to help you if you have questions regarding the usage of the API. They await you on the mailing list.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top