Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
575 views
in Technique[技术] by (71.8m points)

java - Array Index Out Of Bounds Exception when reading tiff image

I have codes here.(Classname=test2.java)

    final String filepath = "brabrabra.tif";
    final String jpg = filepath + ".jpg";
    ImageInputStream iis = null;

    iis = ImageIO.createImageInputStream(new File(filepath));
    Iterator<ImageReader> ite = ImageIO.getImageReaders(iis);
    if (ite != null && ite.hasNext()) {
        ImageReader reader = ite.next();
        reader.setInput(iis);
        int numPage = reader.getNumImages(true);
        IntStream.range(0, numPage).forEach(v -> {
        try {
            BufferedImage tiff = reader.read(v);
            ImageIO.write(tiff, "jpeg", new File(fullpathjpeg));
        } catch (IOException e) {
            e.getMessage();
            e.printStackTrace();
        }
    });

and exception logs

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 1909
at com.sun.media.imageioimpl.plugins.tiff.TIFFFaxDecompressor.decodeT6(TIFFFaxDecompressor.java:1169)
at com.sun.media.imageioimpl.plugins.tiff.TIFFFaxDecompressor.decodeRaw(TIFFFaxDecompressor.java:680)
at com.sun.media.imageio.plugins.tiff.TIFFDecompressor.decode(TIFFDecompressor.java:2514)
at com.sun.media.imageioimpl.plugins.tiff.TIFFImageReader.decodeTile(TIFFImageReader.java:1137)
at com.sun.media.imageioimpl.plugins.tiff.TIFFImageReader.read(TIFFImageReader.java:1417)
at javax.imageio.ImageReader.read(ImageReader.java:939)
at test2.lambda$0(test2.java:44)
at java.util.stream.Streams$RangeIntSpliterator.forEachRemaining(Streams.java:110)
at java.util.stream.IntPipeline$Head.forEach(IntPipeline.java:559)
at test2.main(test2.java:41)

This line gave me an error

BufferedImage tiff = **reader.read(v);**

I don't know why I get this error. Curiously, almost all tiff files were read normally and converted into jpg files, but some were not. I compared tiff files between them but there is no specific difference.(of course I found some differences like size, byte and so on however I don't think those are not related to this error.

Can anyone give me help?


This file is the cause of the problem

differences

question from:https://stackoverflow.com/questions/65896477/array-index-out-of-bounds-exception-when-reading-tiff-image

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...