Java BufferedImage Flip verticalFlip(BufferedImage img)

Here you can find the source of verticalFlip(BufferedImage img)

Description

Flips image raster vertically

License

Open Source License

Parameter

Parameter Description
img A source raster as a BufferedImage

Return

A vertically flipped image raster as a BufferedImage

Declaration

protected static BufferedImage verticalFlip(BufferedImage img) 

Method Source Code

//package com.java2s;
import java.awt.*;

import java.awt.image.*;

public class Main {
    /**/*from   www. j a v a2 s  .  c  o m*/
     * Flips image raster vertically
     *
     * @param img A source raster as a BufferedImage
     *
     * @return A vertically flipped image raster as a BufferedImage
     */
    protected static BufferedImage verticalFlip(BufferedImage img) {
        if (null == img)
            return null;

        int w = img.getWidth();
        int h = img.getHeight();

        //        BufferedImage flipImg = new BufferedImage(w, h, img.getColorModel().getTransparency() );
        BufferedImage flipImg = new BufferedImage(w, h,
                BufferedImage.TYPE_INT_ARGB);
        Graphics2D g2d = flipImg.createGraphics();
        java.awt.Composite prevComposite = g2d.getComposite();
        g2d.setComposite(java.awt.AlphaComposite.Src);
        g2d.drawImage(img, 0, 0, w, h, 0, h, w, 0, null);
        g2d.setComposite(prevComposite);
        g2d.dispose();
        return flipImg;
    }
}

Related

  1. flipVertically(BufferedImage image)
  2. flipVertically(BufferedImage image)
  3. flipVertically(BufferedImage image, RenderingHints hints)
  4. flipVertically(BufferedImage source)
  5. horizontalflip(BufferedImage img)
  6. verticalFlip(BufferedImage img)