Here you can find the source of flipImageHorizontally(BufferedImage image)
Parameter | Description |
---|---|
image | image to be flipped |
public static BufferedImage flipImageHorizontally(BufferedImage image)
//package com.java2s; //License from project: Open Source License import java.awt.*; import java.awt.geom.AffineTransform; import java.awt.image.BufferedImage; public class Main { /**// w w w .j av a 2s .c o m * A method which will invert an image with respect to its y-axis * * @param image image to be flipped * @return a flipped image */ public static BufferedImage flipImageHorizontally(BufferedImage image) { /* Create a new clean image of the same size/type */ BufferedImage flipped = new BufferedImage(image.getWidth(), image.getHeight(), image.getType()); /* Instantiate Affine transformation for flipping and translating */ AffineTransform tran = AffineTransform.getTranslateInstance(image.getWidth(), 0); AffineTransform flip = AffineTransform.getScaleInstance(-1d, 1d); /* Merge these */ tran.concatenate(flip); /* Creates a Graphics2D object linked */ Graphics2D g = flipped.createGraphics(); /* Set the transformation on the graphic */ g.setTransform(tran); /* Draw the image onto the graphic */ g.drawImage(image, 0, 0, null); /* Now dispose of the graphic */ g.dispose(); /* Return the flipped image */ return flipped; } }