我遇到了一个小问题,我有两个库,一个将输出作为java.nio.Buffer发送给我,另一个将输入作为java.nio.ByteBuffer接收,我该如何进行转换?
谢谢。
这个Buffer是来自javaCV的代码:
private BytePointer[] image_ptr;
private Buffer[] image_buf;
// Determine required buffer size and allocate buffer
int size = avpicture_get_size(fmt, width, height);
image_ptr = new BytePointer[] { new BytePointer(av_malloc(size)).capacity(size) };
image_buf = new Buffer[] { image_ptr[0].asBuffer() };
// Assign appropriate parts of buffer to image planes in picture_rgb
// Note that picture_rgb is an AVFrame, but AVFrame is a superset of AVPicture
avpicture_fill(new AVPicture(picture_rgb), image_ptr[0], fmt, width, height);
picture_rgb.format(fmt);
picture_rgb.width(width);
picture_rgb.height(height);
java.nio.Buffer
是一个抽象类。结果的实际类型是什么?它会变化吗?它包含什么? - KayamanByteBuffer
并调用asXxxBuffer().put(...)
来填充它,具体取决于您的Buffer
的实际类型(因此您需要测试它们所有)。 - TunakiBuffer
的实例转换为ByteBuffer
。那里的答案确实可以改进。 - Tunaki