ArrayIndexOutOfBoundsException: 4096 while reading gif file

前端 未结 2 626
一整个雨季
一整个雨季 2020-12-09 03:27

I am able to read png file. But getting ArrayIndexOutOfBoundsException: 4096 while reading gif file.

byte[] fileData = imageFile.getFileData();
ByteArrayInp         


        
2条回答
  •  温柔的废话
    2020-12-09 04:10

    I encountered the exact same problem you did, but I had to stick to an ImageIO interface, which no other library did. Apart from Jack's great answer, I simply patched the existing GIFImageReader class with a few lines of code, and got it marginally working.

    Copy this link into PatchedGIFImageReader.java and use as such:

    reader = new PatchedGIFImageReader(null);
    reader.setInput(ImageIO.createImageInputStream(new FileInputStream(files[i])));
    int ub = reader.getNumImages(true);
    for (int x=0;x

    Be sure to change the package name to whatever you're using.

    Unfortunately results may vary, as the patch was a 1 minute bugfix that basically just exits the loop if it goes past the buffer. Some gifs it loads fine, others have a few visual artifacts.

    Such is life. If anyone knows a better fix instead of mine, please do tell.

提交回复
热议问题