• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Liutauras Vilda
  • Knute Snortum
  • Bear Bibeault
Sheriffs:
  • Devaka Cooray
  • Jeanne Boyarsky
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • salvin francis
Bartenders:
  • Tim Holloway
  • Piet Souris
  • Frits Walraven

Flip/Rotate a BufferedImage

 
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?
 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • 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?
     
    Water! People swim in water! Even tiny ads swim in water:
    Java file APIs (DOC, XLS, PDF, and many more)
    https://products.aspose.com/total/java
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!