Java Utililty Methods BufferedImage Rotate

List of utility methods to do BufferedImage Rotate

Description

The list of methods to do BufferedImage Rotate are organized into topic(s).

Method

BufferedImagerotate(BufferedImage bi, double rotateValue)
rotate
AffineTransform tx = new AffineTransform();
tx.rotate(rotateValue);
AffineTransformOp op = new AffineTransformOp(tx, AffineTransformOp.TYPE_BILINEAR);
BufferedImage biNew = new BufferedImage((bi.getWidth()), (bi.getHeight()), bi.getType());
return op.filter(bi, biNew);
BufferedImagerotate(BufferedImage bi, int degree)
Perform a rotation of the provided BufferedImage using degrees of 90, 180, or 270.
int width = bi.getWidth();
int height = bi.getHeight();
BufferedImage biFlip;
if (degree == 90 || degree == 270)
    biFlip = new BufferedImage(height, width, bi.getType());
else if (degree == 180)
    biFlip = new BufferedImage(width, height, bi.getType());
else
...
BufferedImagerotate(BufferedImage image, double theta)
rotate
boolean swap = Math.round(2.0 * theta / Math.PI) % 2 == 1;
int w = image.getWidth(null);
int h = image.getHeight(null);
double delta = swap ? (w - h) / 2.0 : 0.0;
AffineTransform at = AffineTransform.getTranslateInstance(-delta, delta);
at.rotate(theta, w / 2.0, h / 2.0);
BufferedImage rotated = swap ? createCompatibleImage(h, w) : createCompatibleImage(w, h);
Graphics2D g = (Graphics2D) rotated.getGraphics();
...
BufferedImagerotate(BufferedImage image, double theta, int anchorX, int anchorY)
rotate
return createTransformed(image, AffineTransform.getRotateInstance(theta, anchorX, anchorY));
BufferedImagerotate(BufferedImage image, float theRadiansAngle)
rotate
AffineTransform transform = AffineTransform.getRotateInstance(theRadiansAngle, image.getWidth() / 2,
        image.getHeight() / 2);
AffineTransformOp op = new AffineTransformOp(transform, AffineTransformOp.TYPE_BILINEAR);
return filter(image, op);
BufferedImagerotate(BufferedImage image, int degrees)
Method used to rotate an image based on an inputted degree value
BufferedImage blankCanvas = new BufferedImage(image.getWidth(), image.getHeight(),
        BufferedImage.TYPE_INT_ARGB);
Graphics2D g2D = (Graphics2D) blankCanvas.getGraphics();
g2D.rotate(Math.toRadians(degrees), image.getWidth() / 2, image.getHeight() / 2);
g2D.drawImage(image, 0, 0, null);
return image = blankCanvas;
BufferedImagerotate(BufferedImage img, int angle)
rotate
int w = img.getWidth();
int h = img.getHeight();
BufferedImage dimg = new BufferedImage(w, h, img.getType());
Graphics2D g = dimg.createGraphics();
g.rotate(Math.toRadians(angle), w / 2., h / 2.);
g.drawImage(img, null, 0, 0);
return dimg;
BufferedImagerotate(BufferedImage img, int angle)
rotate
AffineTransform trans;
BufferedImage newImg;
int w = img.getWidth();
int h = img.getHeight();
if (angle == 0) {
    newImg = new BufferedImage(w, h, img.getType());
    trans = null;
} else if (angle == 90) {
...
BufferedImagerotate(BufferedImage img, int angle)
rotate
int w = img.getWidth();
int h = img.getHeight();
BufferedImage dimg = new BufferedImage(w, h, img.getType());
Graphics2D g = dimg.createGraphics();
g.rotate(Math.toRadians(angle), w / 2, h / 2);
g.drawImage(img, null, 0, 0);
return dimg;
BufferedImagerotate(BufferedImage img, int angle)
rotate
double sin = Math.abs(Math.sin(Math.toRadians(angle))), cos = Math.abs(Math.cos(Math.toRadians(angle)));
int w = img.getWidth(null), h = img.getHeight(null);
int neww = (int) Math.floor(w * cos + h * sin), newh = (int) Math.floor(h * cos + w * sin);
BufferedImage bimg = new BufferedImage(neww, newh, img.getType());
Graphics2D g = bimg.createGraphics();
g.translate((neww - w) / 2, (newh - h) / 2);
g.rotate(Math.toRadians(angle), w / 2, h / 2);
g.drawRenderedImage(img, null);
...