flip BufferedImage along Y - Java 2D Graphics

Java examples for 2D Graphics:BufferedImage Rotate

Description

flip BufferedImage along Y

Demo Code


//package com.java2s;

import java.awt.Graphics2D;

import java.awt.geom.AffineTransform;

import java.awt.image.BufferedImage;

public class Main {
    public static BufferedImage flipY(BufferedImage source) {
        BufferedImage output = new BufferedImage(source.getWidth(),
                source.getHeight(), BufferedImage.TYPE_INT_ARGB);
        Graphics2D g2 = output.createGraphics();
        AffineTransform tx = createTransformFlipY(source);
        g2.drawRenderedImage(source, tx);
        return output;
    }//from   ww  w  .j  a  v a  2 s  . co m

    private static AffineTransform createTransformFlipY(BufferedImage source) {
        AffineTransform tx = AffineTransform.getScaleInstance(1, -1);
        tx.translate(0, -source.getHeight());
        return tx;
    }
}

Related Tutorials