Here you can find the source of flip(BufferedImage image, int direction)
Parameter | Description |
---|---|
direction | 0-nothing, 1-horizontal, 2-vertical, 3-both |
public static BufferedImage flip(BufferedImage image, int direction)
//package com.java2s; /*/*from www. ja va 2s. c o m*/ * Copyright (c) 2014 tabletoptool.com team. * All rights reserved. This program and the accompanying materials * are made available under the terms of the GNU Public License v3.0 * which accompanies this distribution, and is available at * http://www.gnu.org/licenses/gpl.html * * Contributors: * rptools.com team - initial implementation * tabletoptool.com team - further development */ import java.awt.Graphics2D; import java.awt.image.BufferedImage; public class Main { /** * Flip the image and return a new image * @param direction 0-nothing, 1-horizontal, 2-vertical, 3-both * @return */ public static BufferedImage flip(BufferedImage image, int direction) { BufferedImage workImage = new BufferedImage(image.getWidth(), image.getHeight(), image.getTransparency()); boolean flipHorizontal = (direction & 1) == 1; boolean flipVertical = (direction & 2) == 2; int workW = image.getWidth() * (flipHorizontal ? -1 : 1); int workH = image.getHeight() * (flipVertical ? -1 : 1); int workX = flipHorizontal ? image.getWidth() : 0; int workY = flipVertical ? image.getHeight() : 0; Graphics2D wig = workImage.createGraphics(); wig.drawImage(image, workX, workY, workW, workH, null); wig.dispose(); return workImage; } }