flip BufferedImage Horizontal - Java 2D Graphics

Java examples for 2D Graphics:BufferedImage Rotate

Description

flip BufferedImage Horizontal

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 flipHorizontal(BufferedImage in) {
        BufferedImage out = new BufferedImage(in.getWidth(),
                in.getHeight(), BufferedImage.TYPE_INT_ARGB);
        Graphics2D g = out.createGraphics();
        double[] tx = { -1, 0, 0, 1, in.getWidth(), 0 };
        g.setTransform(new AffineTransform(tx));
        g.drawImage(in, 0, 0, null);/*from   w w w .ja  va  2  s  . c  o m*/
        return out;
    }
}

Related Tutorials