1

I am having a bufferd-image i.e:

  BufferedImage buffer = ImageIO.read(new File(file));

now i want to rotate it.. So how i can do it??

Previously i have used the image format i.e:

Image image = ImageIO.read(new File(file));

and could easily rotate a image using:

   AffineTransform at = new AffineTransform();
   at.rotate(0.5 * angle * Math.PI, width/2, height/2);

But i dont noe how to do it with the bufferd-image?? Can you help me??

Arizvi
  • 261
  • 1
  • 5
  • 13
  • AffineTransform will work fine if used on a Graphics2D object derived from your BufferedImage, but you'd better take care to choose the correct center of rotation and clipping if the image isn't square. – Hovercraft Full Of Eels Feb 03 '12 at 17:10

1 Answers1

6

Example:

BufferedImage buffer = ImageIO.read(new File(file));
AffineTransform tx = new AffineTransform();
//tx.scale(scalex, scaley);
//tx.shear(shiftx, shifty);
//tx.translate(x, y);
tx.rotate(radians, buffer.getWidth()/2, buffer.getHeight()/2);

AffineTransformOp op = new AffineTransformOp(tx, AffineTransformOp.TYPE_BILINEAR);
buffer = op.filter(buffer, null);

See also:

Community
  • 1
  • 1
kaliatech
  • 17,579
  • 5
  • 72
  • 84
  • The two links at bottom show how to recenter if needed. This question should probably be marked as a duplicate. – kaliatech Feb 03 '12 at 17:18
  • You can add my answer to your links: [affinetransform-truncates-image-what-do-i-wrong](http://stackoverflow.com/questions/8719473/affinetransform-truncates-image-what-do-i-wrong/8720123#8720123) – Hovercraft Full Of Eels Feb 03 '12 at 17:29