0

我正在使用 ImageIO api 读取字节数组(使用 ByteArrayInputStream)以取回 BufferredImage。它大部分时间都有效,但对于某些图像会失败。经过广泛的研究 - 我发现它与颜色转换有关。但是我不确定如何通过不放弃 ImageIO API 来快速解决这个问题。下面是堆栈跟踪:

java.lang.IllegalArgumentException: Numbers of source Raster bands and source color space components do not match
   at java.awt.image.ColorConvertOp.filter(ColorConvertOp.java:460)
   at com.sun.imageio.plugins.jpeg.JPEGImageReader.acceptPixels(JPEGImageReader.java:1114)
   at com.sun.imageio.plugins.jpeg.JPEGImageReader.readImage(JPEGImageReader.java:0)
   at com.sun.imageio.plugins.jpeg.JPEGImageReader.readInternal(JPEGImageReader.java:1082)
   at com.sun.imageio.plugins.jpeg.JPEGImageReader.read(JPEGImageReader.java:897)
   at javax.imageio.ImageIO.read(ImageIO.java:1422)
   at javax.imageio.ImageIO.read(ImageIO.java:1374)
   at org.netbeans.modules.form.editors.CustomIconEditor$IconFileItem.<init>(CustomIconEditor.java:516)
   at org.netbeans.modules.form.editors.CustomIconEditor.createFileComboModel(CustomIconEditor.java:479)
   at org.netbeans.modules.form.editors.CustomIconEditor.setPackage(CustomIconEditor.java:312)
   at org.netbeans.modules.form.editors.CustomIconEditor.setValue(CustomIconEditor.java:155)
   at org.netbeans.modules.form.editors.IconEditor.getCustomEditor(IconEditor.java:228)
   at org.netbeans.modules.form.ResourceWrapperEditor.createCustomEditorGUI(ResourceWrapperEditor.java:311)
   at org.netbeans.modules.form.ResourceWrapperEditor.getCustomEditor(ResourceWrapperEditor.java:203)
   at org.netbeans.modules.form.FormPropertyEditor.getCustomEditor(FormPropertyEditor.java:303)
   at org.openide.explorer.propertysheet.PropertyDialogManager.<init>(PropertyDialogManager.java:129)
   at org.openide.explorer.propertysheet.CustomEditorAction.actionPerformed(CustomEditorAction.java:217)
   at org.openide.explorer.propertysheet.SheetTable.editCellAt(SheetTable.java:998)
   at javax.swing.plaf.basic.BasicTableUI$Handler.adjustSelection(BasicTableUI.java:1078)
   at javax.swing.plaf.basic.BasicTableUI$Handler.mousePressed(BasicTableUI.java:1008)
   at java.awt.AWTEventMulticaster.mousePressed(AWTEventMulticaster.java:263)
   at java.awt.AWTEventMulticaster.mousePressed(AWTEventMulticaster.java:262)
   at java.awt.AWTEventMulticaster.mousePressed(AWTEventMulticaster.java:262)
   at java.awt.Component.processMouseEvent(Component.java:6260)
   at javax.swing.JComponent.processMouseEvent(JComponent.java:3255)
   at org.openide.explorer.propertysheet.SheetTable.processMouseEvent(SheetTable.java:731)
   at java.awt.Component.processEvent(Component.java:6028)
   at java.awt.Container.processEvent(Container.java:2041)
   at java.awt.Component.dispatchEventImpl(Component.java:4630)
   at java.awt.Container.dispatchEventImpl(Container.java:2099)
   at java.awt.Component.dispatchEvent(Component.java:4460)
   at java.awt.LightweightDispatcher.retargetMouseEvent(LightweightDispatcher.java:4574)
   at java.awt.LightweightDispatcher.processMouseEvent(LightweightDispatcher.java:4235)
   at java.awt.LightweightDispatcher.dispatchEvent(LightweightDispatcher.java:4168)
   at java.awt.Container.dispatchEventImpl(Container.java:2085)
   at java.awt.Window.dispatchEventImpl(Window.java:2475)
   at java.awt.Component.dispatchEvent(Component.java:4460)
   at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
   at org.netbeans.core.TimableEventQueue.dispatchEvent(TimableEventQueue.java:104)
   at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
   at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
   at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
   at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
   at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
   at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
4

2 回答 2

1

因此,这是 javax.imageio API 中的一个 JDK 错误,它阻止 ImageIO.read(..) 返回一个 BufferedImage。它在 2007 年被报道并且仍然开放:(

http://bugs.sun.com/view_bug.do;jsessionid=2e30e4710093bcffffffffa4c93719b2921d5?bug_id=6619667

为了解决我的问题 - 我已经实施了一种解决方法来直接处理字节。生活很好。感谢您抽出时间)

于 2013-01-18T20:29:21.657 回答
1

该错误消息提供信息,表明 ICC 颜色配置文件中提到的光栅带的数量似乎不正确。我使用ImageMagick从图像中剥离ICC 配置文件。ImageIO 随后在读取图像时没有问题(~1k 坏图像)。希望有帮助。

于 2013-03-27T06:40:26.323 回答