Java BufferedImage Transform transform(BufferedImage image, int numquadrants)

Here you can find the source of transform(BufferedImage image, int numquadrants)

Description

transform

License

Apache License

Declaration

public static BufferedImage transform(BufferedImage image, int numquadrants) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

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

public class Main {
    public static BufferedImage transform(BufferedImage image, int numquadrants) {
        int w0 = image.getWidth();
        int h0 = image.getHeight();
        int w1 = w0;
        int h1 = h0;

        int centerX = w0 / 2;
        int centerY = h0 / 2;

        if (numquadrants % 2 == 1) {
            w1 = h0;//from   w  w w .  j  av  a 2  s. co  m
            h1 = w0;
        }

        if (numquadrants % 4 == 1) {
            if (w0 > h0) {
                centerX = h0 / 2;
                centerY = h0 / 2;
            } else if (h0 > w0) {
                centerX = w0 / 2;
                centerY = w0 / 2;
            }
            // if h0 == w0, then use default
        } else if (numquadrants % 4 == 3) {
            if (w0 > h0) {
                centerX = w0 / 2;
                centerY = w0 / 2;
            } else if (h0 > w0) {
                centerX = h0 / 2;
                centerY = h0 / 2;
            }
            // if h0 == w0, then use default
        }

        AffineTransform affineTransform = new AffineTransform();
        affineTransform.setToQuadrantRotation(numquadrants, centerX, centerY);

        AffineTransformOp opRotated = new AffineTransformOp(affineTransform, AffineTransformOp.TYPE_BILINEAR);

        BufferedImage transformedImage = new BufferedImage(w1, h1, image.getType());

        transformedImage = opRotated.filter(image, transformedImage);
        return transformedImage;
    }
}

Related

  1. copyAndTranslateSubimage(BufferedImage src, Rectangle bounds)
  2. getTransformedImage(BufferedImage image, double scaleX, double scaleY, double shearX, double shearY)
  3. transform(BufferedImage image, int sx, int sy, int dx, int dy)
  4. transform(String originalFile, String thumbnailFile, int thumbWidth, int thumbHeight)
  5. TransformGrayToTransparency(BufferedImage image)
  6. transformGrayToTransparency(BufferedImage image)