Here you can find the source of flipVertical(BufferedImage im)
public static BufferedImage flipVertical(BufferedImage im)
//package com.java2s; //License from project: LGPL import java.awt.image.*; public class Main { public static BufferedImage flipVertical(BufferedImage im) { int height = im.getHeight(); int width = im.getWidth(); DataBuffer db = im.getRaster().getDataBuffer(); if (db instanceof DataBufferInt) { int imdata[] = ((DataBufferInt) db).getData(); BufferedImage im2 = new BufferedImage(width, height, im.getType()); int imdata2[] = ((DataBufferInt) (im2.getRaster().getDataBuffer())).getData(); int stride = width; for (int y = 0; y < height; y++) System.arraycopy(imdata, y * stride, imdata2, (height - 1 - y) * stride, stride); return im2; }//w w w .j a v a2s . c om if (db instanceof DataBufferByte) { byte imdata[] = ((DataBufferByte) db).getData(); BufferedImage im2 = new BufferedImage(width, height, im.getType()); byte imdata2[] = ((DataBufferByte) (im2.getRaster().getDataBuffer())).getData(); int bytes_per_pixel = 0; switch (im.getType()) { case BufferedImage.TYPE_4BYTE_ABGR: case BufferedImage.TYPE_4BYTE_ABGR_PRE: bytes_per_pixel = 4; break; case BufferedImage.TYPE_3BYTE_BGR: bytes_per_pixel = 3; break; case BufferedImage.TYPE_BYTE_GRAY: bytes_per_pixel = 1; break; case BufferedImage.TYPE_BYTE_BINARY: case BufferedImage.TYPE_BYTE_INDEXED: return null; //XXX These types are not supported by this method } int stride = bytes_per_pixel * width; for (int y = 0; y < height; y++) System.arraycopy(imdata, y * stride, imdata2, (height - 1 - y) * stride, stride); return im2; } assert (false); return null; } }