Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
The moose likes Swing / AWT / SWT and the fly likes Rotating a buffered image Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Rotating a buffered image" Watch "Rotating a buffered image" New topic

Rotating a buffered image

Alireza Bahmanpour

Joined: Oct 24, 2007
Posts: 23

I wanted to write a method which gets a buffered image as parameter, rotates it 90 degrees clockwise around its top left corner, and then returns it. This method will be call from another method which then draws the rotated image on a rather large background which consists of many other images.

Here is the code I have so far

This method does rotate an image 90 degrees, but when the calling method recieves this image and displays it on the bigger frame, parts of the rotated image is cut. I think because the frame holding the returned image is not big enough. I've tried playing around with the code a lot, chaging the sizes of different images, and trying AffineTransform features, but I have had no luck.

I would greatly appreciate any help

Thanks in advance
Rob Spoor

Joined: Oct 27, 2005
Posts: 20132

Let's move this to our GUI forum.

How To Ask Questions How To Answer Questions
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2383
The Rotated Icon allows you to treat an Image like an Icon which gives it more flexibility as you can just draw the Icon or add the Icon to any Swing component that supports Icons. It will also handle non square Icons.

Or you can take a look at this example.
Carey Brown
Ranch Hand

Joined: Nov 19, 2001
Posts: 779

How about something like...

When I was your age I was toggling in the bootstrap code on the front panel
Prince Mathew

Joined: Jul 13, 2014
Posts: 1
Swapping the values of 'w' and 'h' here will solve this problem. ie. No portion of the image will be lost.
I agree. Here's the link:
subject: Rotating a buffered image
It's not a secret anymore!