title: Java How to convert a java.nio.Buffer into a ByteBuffer
body: <p>I'm facing a little problem I have two libraries one send me the output as java.nio.Buffer and the other receives the input as a java.nio.ByteBuffer how do I make the conversion?</p>
  
  <p>Thanks</p>
  
  <p>the Buffer is from javaCV from this piece of code:</p>
  
  <pre><code>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);
  </code></pre>