【问题标题】:The 11th image is never recognized by the reader第 11 张图像永远无法被读者识别
【发布时间】:2019-06-06 11:15:03
【问题描述】:

我正在尝试将 gif 转换为缓冲图像的 Arraylist。我之前使用过Convert each animated GIF frame to a separate BufferedImage 的一段代码,但它返回的缓冲图像中每个像素都是相同的颜色。因此,我决定改用这个:

public ArrayList<BufferedImage> getFrames(File gif) throws IOException {
        ArrayList<BufferedImage> frames = new ArrayList<BufferedImage>();
        try {
            ImageReader reader = ImageIO.getImageReadersByFormatName("gif").next();
            ImageInputStream stream = ImageIO.createImageInputStream(gif);
            reader.setInput(stream);
            int count = reader.getNumImages(true);
            System.out.println("count is "+count);
            for (int index = 0; index < count; index++) {
                System.out.println("index is "+index);
                BufferedImage frame = reader.read(index);
                frames.add(frame);
            }
        } catch (IOException ex) {
            System.out.println("An I/O problem has occurred");
        }
        return frames;
}

输出表明第10张图片有错误:

count is 70
index is 0
index is 1
index is 2
index is 3
index is 4
index is 5
index is 6
index is 7
index is 8
index is 9
index is 10
Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 4096

我想知道:为什么是 10?导致此问题的第 11 个图像会发生什么?如何修复错误以便我可以拥有全部 70 帧?

这是其余的错误(添加了堆栈跟踪):

at com.sun.imageio.plugins.gif.GIFImageReader.read(Unknown Source)
    at javax.imageio.ImageReader.read(Unknown Source)
    at Pointilismo.getFrames(Pointilismo.java:104)
    at Pointilismo.updateimage(Pointilismo.java:116)
    at Pointilismo.switchimage(Pointilismo.java:135)
    at Pointilismo.actionPerformed(Pointilismo.java:210)
    at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
    at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
    at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
    at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
    at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
    at java.awt.Component.processMouseEvent(Unknown Source)
    at javax.swing.JComponent.processMouseEvent(Unknown Source)
    at java.awt.Component.processEvent(Unknown Source)
    at java.awt.Container.processEvent(Unknown Source)
    at java.awt.Component.dispatchEventImpl(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
    at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
    at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Window.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
    at java.awt.EventQueue.access$500(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
    at java.awt.EventQueue$4.run(Unknown Source)
    at java.awt.EventQueue$4.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)

【问题讨论】:

  • 您是否有堆栈跟踪,以便获得有关异常确切位置的更多信息?
  • @Conffusion 我已添加并更新以显示错误消息的其余部分。

标签: image io


【解决方案1】:

我没有任何图像处理经验,但发现可能是您的问题的原因: bug

【讨论】:

    猜你喜欢
    • 2014-01-09
    • 2017-12-07
    • 2015-07-12
    • 2020-02-27
    • 2021-03-30
    • 2015-06-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多