Java BufferedImage Rotate rotateImages(BufferedImage imgs[], double angle)

Here you can find the source of rotateImages(BufferedImage imgs[], double angle)

Description

rotateImages
   public static BufferedImage[] rotateImages(BufferedImage imgs[],  double angle)

This is a delegator method for the method 'rotateImage' but this method allows for a whole array to be rotated.

License

Open Source License

Parameter

Parameter Description

Return

BufferedImage[]

Declaration

public static BufferedImage[] rotateImages(BufferedImage imgs[], double angle) 

Method Source Code

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

import java.awt.geom.AffineTransform;
import java.awt.image.AffineTransformOp;
import java.awt.image.BufferedImage;
import java.awt.image.ColorModel;
import java.awt.image.WritableRaster;

public class Main {
    /**//from w ww .  ja  v  a  2s .c o m
     * <i><b>rotateImages</b></i>
     * <pre>   public static BufferedImage[] rotateImages(BufferedImage imgs[], 
     *                                                          double angle)</pre>
     * <p>This is a delegator method for the method 'rotateImage' but this method allows for a whole array to be rotated.</p>
     * @param
     * @return BufferedImage[]
     * **/
    public static BufferedImage[] rotateImages(BufferedImage imgs[], double angle) {
        BufferedImage[] rotated_copy = copyImages(imgs);
        for (int i = 0; i < imgs.length; i++) {
            rotated_copy[i] = rotateImage(rotated_copy[i], angle);
        }
        return rotated_copy;

    }

    /**
     * <i><b>copyImages</b></i>
     * <pre>   public BufferedImage[] copyImages(BufferedImage[] imgs)</pre>
     * <p>This method delegates to the copyImage(img) method for each of the images stored in the array.</p>
     * @param
     * @return BufferedImage[]
     * **/
    public static BufferedImage[] copyImages(BufferedImage[] imgs) {
        BufferedImage[] copy = new BufferedImage[imgs.length];
        for (int i = 0; i < imgs.length; i++) {
            copy[i] = copyImage(imgs[i]);
        }
        return copy;
    }

    /**
     * <i><b>rotateImage</b></i>
     * <pre>   public static BufferedImage rotateImage(BufferedImage img, 
     *                                                       double angle)</pre>
     * <p>This method rotates the parsed image to the parsed angle.</p>
     * @param
     * @return BufferedImage
     * @see {@link dev.lucas.game.utils}
     * **/
    public static BufferedImage rotateImage(BufferedImage img, double angle) {
        int w = img.getWidth();
        int h = img.getHeight();
        AffineTransform tx = new AffineTransform();
        tx.translate(w / 2, h / 2);
        tx.rotate(angle);
        tx.scale(1, 1);
        tx.translate(-w / 2, -h / 2);
        AffineTransformOp op = new AffineTransformOp(tx, AffineTransformOp.TYPE_BILINEAR);
        return op.filter(img, null);

    }

    /**
     * <i><b>copyImage</b></i>
     * <pre>   public static BufferedImage copyImage(BufferedImage img)</pre>
     * <p>This method makes a copy of the parsed BufferedImage.</p>
     * @param
     * @return BufferedImage
     * **/
    public static BufferedImage copyImage(BufferedImage img) {
        ColorModel cm = img.getColorModel();
        boolean isAlphaPreMultiplied = cm.isAlphaPremultiplied();
        WritableRaster raster = img.copyData(img.getRaster().createCompatibleWritableRaster());
        return new BufferedImage(cm, raster, isAlphaPreMultiplied, null);
    }
}

Related

  1. rotateImage(final BufferedImage savedImage, final int angle)
  2. rotateImage(final BufferedImage src, final double degrees)
  3. rotateImage180(BufferedImage image, final int bufferedImageType)
  4. rotateImageLeft90( BufferedImage bufferedimage)
  5. rotateImageRect(final BufferedImage image, final int degrees)
  6. RotateLeft(BufferedImage bi)
  7. rotateLeft(BufferedImage image, RenderingHints hints)
  8. rotateMyImage(BufferedImage img, double angle)