aspose file tools*
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


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Flip/Rotate a BufferedImage" Watch "Flip/Rotate a BufferedImage" New topic
Author

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: 15286
    
    6

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 - A Test Data Generation Platform
    Peter Chase
    Ranch Hand

    Joined: Oct 30, 2001
    Posts: 1970
    Thanks.

    Can I draw the transformed image to the Graphics of the original BufferedImage? Or do I need to make a new, appropriately-sized, BufferedImage?
     
     
    subject: Flip/Rotate a BufferedImage
     
    Similar Threads
    new image after rotate
    problem with Graphics2D.rotate()
    need help creating a method for rotate
    way to rotate without using Graphics2D.rotate()
    Rotating a buffered image