Java BufferedImage Flip flipVertically(BufferedImage image)

Here you can find the source of flipVertically(BufferedImage image)

Description

flip Vertically

License

Open Source License

Declaration

public static BufferedImage flipVertically(BufferedImage image) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Rectangle;

import java.awt.geom.AffineTransform;

import java.awt.image.BufferedImage;

public class Main {
    public static BufferedImage flipVertically(BufferedImage image) {
        return transform(image, 1, -1, 0, -image.getHeight());
    }/*w ww . j  a va 2  s. c  o  m*/

    private static BufferedImage transform(BufferedImage image, int sx, int sy, int dx, int dy) {
        AffineTransform at = new AffineTransform();

        at.concatenate(AffineTransform.getScaleInstance(sx, sy));
        at.concatenate(AffineTransform.getTranslateInstance(dx, dy));

        return createTransformed(image, at);
    }

    private static BufferedImage createTransformed(BufferedImage image, AffineTransform at) {
        BufferedImage newImage = createImage(image);
        Graphics2D g = newImage.createGraphics();

        g.transform(at);
        g.drawImage(image, 0, 0, null);
        g.dispose();

        return newImage;
    }

    public static BufferedImage createImage(Rectangle bounds) {
        return createImage(bounds, BufferedImage.TYPE_INT_ARGB);
    }

    public static BufferedImage createImage(Rectangle bounds, int type) {
        return createImage(bounds.width, bounds.height, type);
    }

    public static BufferedImage createImage(Image image) {
        return createImage(image, BufferedImage.TYPE_INT_ARGB);
    }

    public static BufferedImage createImage(Image image, int type) {
        return createImage(image.getWidth(null), image.getHeight(null), type);
    }

    public static BufferedImage createImage(int width, int height) {
        return createImage(width, height, BufferedImage.TYPE_INT_ARGB);
    }

    public static BufferedImage createImage(int width, int height, int type) {
        return new BufferedImage(width, height, type);
    }
}

Related

  1. flipImage(final BufferedImage image, final boolean horizontal, final boolean vertical)
  2. flipImage(Object original, boolean flipX, boolean flipY)
  3. flipImageHorizontally(BufferedImage image)
  4. flipImageVertically(BufferedImage theImage)
  5. flipVertical(BufferedImage im)
  6. flipVertically(BufferedImage image)
  7. flipVertically(BufferedImage image, RenderingHints hints)
  8. flipVertically(BufferedImage source)
  9. horizontalflip(BufferedImage img)