Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Flip/Rotate a BufferedImage

 
Peter Chase
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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)

  •  
    Peter Chase
    Ranch Hand
    Posts: 1970
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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?
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic