File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes Flip/Rotate a BufferedImage Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Flip/Rotate a BufferedImage" Watch "Flip/Rotate a BufferedImage" New topic

Flip/Rotate a BufferedImage

Peter Chase
Ranch Hand

Joined: Oct 30, 2001
Posts: 1970
I have a BufferedImage. It was made from a PixelInterleavedSampleModel, via a Raster. I would like to flip (horizonatal or vertical) or rotate (multiples of 90 degrees) the image.

The result that I require is a BufferedImage. It would be OK to perform the transformations in-place on the original BufferedImage, if that were possible.

My images are for the Web and will take up about half a screen. That is, they're quite big but not huge.

What is the most efficient way to achieve flipping and/or rotating of the text?

I've seen AffineTransform. Is that the way forward? If so, can someone help me with the steps?

Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15302

Steps necessary:

  • Create: AffineTransform trans = new AffineTransform()
  • Scale: trans.scale(scalex, scaley)
  • Shear: trans.shear(shiftx, shifty)
  • Translate: trans.translate(deltax, deltay)
  • Rotate: trans.rotate(radians)
  • Draw: g2d.drawImage(image, trans, this)

  • GenRocket - Experts at Building Test Data
    Peter Chase
    Ranch Hand

    Joined: Oct 30, 2001
    Posts: 1970

    Can I draw the transformed image to the Graphics of the original BufferedImage? Or do I need to make a new, appropriately-sized, BufferedImage?
    I agree. Here's the link:
    subject: Flip/Rotate a BufferedImage
    It's not a secret anymore!