Here you can find the source of flipImageVertically(BufferedImage theImage)
Parameter | Description |
---|---|
theImage | the image to flip |
public static void flipImageVertically(BufferedImage theImage)
//package com.java2s; /*//from w ww . j a v a 2 s .c om * Copyright (c) 2013 christianr. * All rights reserved. This program and the accompanying materials * are made available under the terms of the GNU Lesser Public License v3 * which accompanies this distribution, and is available at * http://www.gnu.org/licenses/lgpl-3.0.html * * Contributors: * christianr - initial API and implementation */ import java.awt.image.BufferedImage; import java.awt.image.WritableRaster; public class Main { /** * Flips the supplied BufferedImage vertically. This is often a necessary * conversion step to display a Java2D image correctly with OpenGL and vice * versa. * * @param theImage the image to flip */ public static void flipImageVertically(BufferedImage theImage) { WritableRaster raster = theImage.getRaster(); Object scanline1 = null; Object scanline2 = null; for (int i = 0; i < theImage.getHeight() / 2; i++) { scanline1 = raster.getDataElements(0, i, theImage.getWidth(), 1, scanline1); scanline2 = raster.getDataElements(0, theImage.getHeight() - i - 1, theImage.getWidth(), 1, scanline2); raster.setDataElements(0, i, theImage.getWidth(), 1, scanline2); raster.setDataElements(0, theImage.getHeight() - i - 1, theImage.getWidth(), 1, scanline1); } } }