在Java中将IBuffer转换为字节数组
我使用了Xuggler教程来解码和播放视频。 我需要查看每一帧的原始数据。 我使用的方法getData如下:在Java中将IBuffer转换为字节数组,java,buffer,bytearray,Java,Buffer,Bytearray,我使用了Xuggler教程来解码和播放视频。 我需要查看每一帧的原始数据。 我使用的方法getData如下: IBuffer img = picture.getData(); 如何在Java中将IBuffer img转换为字节数组 谢谢 编辑 我发现了以下命令: java.nio.ByteBuffer buffer = img.getByteBuffer(0, bufSize);//bytebuffer byte[] bytes = new byte[10]; // Create
IBuffer img = picture.getData();
如何在Java中将IBuffer img转换为字节数组
谢谢
编辑
我发现了以下命令:
java.nio.ByteBuffer buffer = img.getByteBuffer(0, bufSize);//bytebuffer
byte[] bytes = new byte[10]; // Create a byte array
ByteBuffer buf=buffer.wrap(bytes); // Wrap a byte array into a buffer
bytes = new byte[buf.remaining()]; // Retrieve bytes between the position and limit
// (see Putting Bytes into a ByteBuffer)
buf.get(bytes, 0, bytes.length); // transfer bytes from this buffer into the given destination array
buf.clear(); // Retrieve all bytes in the buffer
bytes = new byte[buf.capacity()];
// transfer bytes from this buffer into the given destination array
buf.get(bytes, 0, bytes.length);
System.out.println(bytes);
输出为:
[B@1ccd51b
[B@215eee
[B@1e579dc
[B@14793a8
[B@1082746
它们的长度不一样,对吗
我使用了:
System.out.println(Arrays.toString(bytes));
要打印出字节数组内容,但输出如下所示:
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
我怎样才能解决这个问题
谢谢您打印了对字节数组的引用。这只是一个内存地址。遍历数组并打印每个数组。打印方式不正确。谢谢您的帮助。我已经尝试过:System.out.println(Arrays.toString(bytes));System.out.println(Integer.toHexString(theByte));但输出都是零