Here you can find the source of copyByteBuffer(ByteBuffer srcBuf, int srcStep, ByteBuffer dstBuf, int dstStep)
private static void copyByteBuffer(ByteBuffer srcBuf, int srcStep, ByteBuffer dstBuf, int dstStep)
//package com.java2s; //License from project: Open Source License import java.nio.ByteBuffer; public class Main { private static void copyByteBuffer(ByteBuffer srcBuf, int srcStep, ByteBuffer dstBuf, int dstStep) { assert srcBuf != dstBuf; int channels = 3; int w = Math.min(srcStep, dstStep); int srcLine = srcBuf.position(), dstLine = dstBuf.position(); byte[] buffer = new byte[channels]; while (srcLine < srcBuf.capacity() && dstLine < dstBuf.capacity()) { srcBuf.position(srcLine);//w w w .j av a 2 s .c om dstBuf.position(dstLine); w = Math.min(Math.min(w, srcBuf.remaining()), dstBuf.remaining()); for (int x = 0; x < w; x += channels) { for (int z = 0; z < channels; z++) { int in = srcBuf.get(); byte out; out = (byte) in; buffer[z] = out; } for (int z = channels - 1; z >= 0; z--) { dstBuf.put(buffer[z]); } } srcLine += srcStep; dstLine += dstStep; } } }