java.awt.image.RasterFormatException:数据数组太小(应该是> 388799)

时间:2015-08-06 05:26:47

标签: image converter bufferedimage xuggler xuggle

我正在尝试使用 Xuggle 库中包含的IConverter类进行一些图像处理,以将图像从IVideoPicture类型转换为BufferedImage类型但是我遇到了标题中的错误。

这是我的代码:

BufferedImage orgnlimage = new BufferedImage(Picture.getWidth(), Picture.getHeight(), BufferedImage.TYPE_3BYTE_BGR);
IConverter converter = ConverterFactory.createConverter(orgnlimage, IPixelFormat.Type.BGR24);
orgnlimage = converter.toImage(Picture); // Exception on this line

相关图片的尺寸 360x360

这是我得到的例外:

Exception in thread "main" java.awt.image.RasterFormatException: Data array too small (should be > 388799 )
    at sun.awt.image.ByteComponentRaster.verify(ByteComponentRaster.java:947)
    at sun.awt.image.ByteComponentRaster.<init>(ByteComponentRaster.java:201)
    at sun.awt.image.ByteInterleavedRaster.<init>(ByteInterleavedRaster.java:191)
    at sun.awt.image.ByteInterleavedRaster.<init>(ByteInterleavedRaster.java:113)
    at java.awt.image.Raster.createWritableRaster(Raster.java:980)
    at com.xuggle.xuggler.video.BgrConverter.toImage(BgrConverter.java:195)
    at xuggler.Encrypt.main(Encrypt.java:53)
    at xuggler.DecodeAndSaveAudioVideo.main(DecodeAndSaveAudioVideo.java:141)

我的第二次尝试:

public IVideoPicture main(IVideoPicture Picture) throws NoSuchPaddingException, IllegalBlockSizeException, BadPaddingException, IOException
{ 
        int width = Picture.getWidth();
        int height = Picture.getHeight();
        long timestamp = Picture.getTimeStamp();

BufferedImage orgnlimage = videoPictureToImage(Picture);


        byte[] orgnlimagebytes =toByte(orgnlimage); 
        byte[] encryptedbytes = encrypt(orgnlimagebytes, "abc");
        //System.out.println(encryptedbytes.length);

        BufferedImage encryptedimage = toImage(encryptedbytes, width, height);   

        String desc = ConverterFactory.findDescriptor(encryptedimage);
       IConverter converter = ConverterFactory.createConverter(desc, Picture);


        IVideoPicture Pic = converter.toPicture(encryptedimage, timestamp);

        return Pic;

}  

和堆栈跟踪:

Exception in thread "main" java.nio.BufferOverflowException
at java.nio.DirectByteBuffer.put(DirectByteBuffer.java:363)
at java.nio.ByteBuffer.put(ByteBuffer.java:859)
at com.xuggle.xuggler.video.BgrConverter.toPicture(BgrConverter.java:132)
at xuggler.Encrypt.main(Encrypt.java:62)
at xuggler.DecodeAndSaveAudioVideo.main(DecodeAndSaveAudioVideo.java:141)

1 个答案:

答案 0 :(得分:1)

问题在于,由于某种原因,Xuggler BgrConverter.toImage()方法尝试在大小为byte的{​​{1}}数组周围创建一个栅格,这个数字短一个字节......它应该大小为388799388800),用于BGR格式的图片。

我说file a bug report

或者试试Humble Video,这似乎是Xuggler的继承者。