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

Imagerotate(BufferedImage img, int b, int a, int angle)
rotate
int w = img.getWidth();
int h = img.getHeight();
BufferedImage dimg = new BufferedImage(w, h, img.getType());
Graphics2D g = dimg.createGraphics();
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, 
        RenderingHints.VALUE_ANTIALIAS_ON);
g.rotate(Math.toRadians(angle), w / 2, h / 2);
g.drawImage(img, null, 0, 0);
...
BufferedImagerotate(BufferedImage source, int angle)
Rotates a given image to a given angle.
w = source.getWidth();
h = source.getHeight();
bimg = new BufferedImage(w, h, source.getType());
g2 = bimg.createGraphics();
g2.rotate(Math.toRadians(angle), w / 2, h / 2);
g2.drawImage(source, null, 0, 0);
return bimg;
BufferedImagerotate(BufferedImage src)
rotate
int width = src.getWidth();
int height = src.getHeight();
BufferedImage rotated = new BufferedImage(height, width, src.getColorModel().getTransparency());
for (int i = 0; i < width; ++i) {
    for (int j = 0; j < height; ++j) {
        rotated.setRGB(j, width - i - 1, src.getRGB(i, j));
return rotated;
BufferedImagerotate(final BufferedImage image, final int angle)
Rotates given image to given angle.
if (image == null) {
    throw new IllegalArgumentException("\"image\" param cannot be null.");
final int imageWidth = image.getWidth();
final int imageHeight = image.getHeight();
final Map<String, Integer> boundingBoxDimensions = calculateRotatedDimensions(imageWidth, imageHeight,
        angle);
final int newWidth = boundingBoxDimensions.get("width");
...
voidrotate(Graphics2D g, BufferedImage newImg, int x, int y, int width, int height, int angle, int originX, int originY)
rotate
AffineTransform tmp = g.getTransform();
AffineTransform trans = new AffineTransform();
trans.rotate(angle, x + originX, y + originY);
g.transform(trans);
g.drawImage(newImg, x, y, width, height, null);
g.setTransform(tmp);
BufferedImagerotate90(BufferedImage bi)
Rotate a BufferedImage 90 degrees clockwise.
BufferedImage result = null;
if (bi != null) {
    int w = bi.getWidth();
    int h = bi.getHeight();
    int endw = h;
    int endh = w;
    int max = w;
    if (h > w) {
...
BufferedImagerotate90(BufferedImage img, boolean left)
Rotate the image 90 degrees
int w = img.getWidth(null);
int h = img.getHeight(null);
double angle = (left ? -90 : 90);
BufferedImage rotatedImage = new BufferedImage(h, w, BufferedImage.TYPE_INT_RGB);
AffineTransform trans = new AffineTransform();
trans.rotate(Math.toRadians(angle));
if (left) {
    trans.translate(-w, 0);
...
BufferedImagerotate90ToRight(BufferedImage inputImage)
rotate an Image 90 Degrees to the Right
int width = inputImage.getWidth();
int height = inputImage.getHeight();
BufferedImage returnImage = new BufferedImage(height, width, inputImage.getType());
for (int x = 0; x < width; x++) {
    for (int y = 0; y < height; y++) {
        returnImage.setRGB(height - y - 1, x, inputImage.getRGB(x, y));
return returnImage;
BufferedImagerotateAndFlipSwappingRowsAndColumns(BufferedImage srcImage)
rotate And Flip Swapping Rows And Columns
int srcWidth = srcImage.getWidth();
int srcHeight = srcImage.getHeight();
ColorModel srcColorModel = srcImage.getColorModel();
SampleModel srcSampleModel = srcImage.getSampleModel();
WritableRaster srcRaster = srcImage.getRaster();
DataBuffer srcDataBuffer = srcRaster.getDataBuffer();
int srcDataBufferOffset = srcDataBuffer.getOffset();
int srcNumBands = srcRaster.getNumBands();
...
BufferedImagerotateBufferedImage(BufferedImage bufferedImage, double angle)
rotate Buffered Image
BufferedImage bufferedImageFixed = new BufferedImage(bufferedImage.getWidth(), bufferedImage.getHeight(),
        bufferedImage.getType());
AffineTransform at = new AffineTransform();
at.rotate(angle, (bufferedImage.getWidth() / 2.0), (bufferedImage.getHeight() / 2.0));
AffineTransformOp ato = new AffineTransformOp(at, AffineTransformOp.TYPE_BILINEAR);
ato.filter(bufferedImage, bufferedImageFixed);
return bufferedImageFixed;