Here you can find the source of flip(ByteBuffer bytes, int width, int height)
public static void flip(ByteBuffer bytes, int width, int height)
//package com.java2s; //License from project: Open Source License import java.nio.ByteBuffer; public class Main { public static void flip(byte[] bytes, int width, int height) { byte[] line = new byte[width]; for (int i = 0; i < height / 2; i++) { System.arraycopy(bytes, i * width, line, 0, width); System.arraycopy(bytes, (height - i - 1) * width, bytes, i * width, width); System.arraycopy(line, 0, bytes, (height - i - 1) * width, width); }//ww w . j a v a2 s . c o m } public static void flip(ByteBuffer bytes, int width, int height) { byte[] line = new byte[width]; byte[] line2 = new byte[width]; for (int i = 0; i < height / 2; i++) { bytes.position(i * width); bytes.get(line); bytes.position((height - i - 1) * width); bytes.get(line2); bytes.position(i * width); bytes.put(line2); bytes.position((height - i - 1) * width); bytes.put(line); } } }