This week's book giveaway is in the OCPJP forum. We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line! See this thread for details.
I am working on a project where I need to rotate multiple images. I have no problem rotating the image multiple ways, but with affine transform the corners get cut off when rotating at weird angles, and if enlarge the size of the buffered image to remedy this, then the image size gets larger, although some of it is nonvisible space. does anyone know of any way to rotate an image with more control, i.e. getting down to the pixel level, and would this method allow me more control over the image rotation and painting?
As far as I remember, setToRotation() sets only one Transform, so any other transforms are lost.
You can of course use the matrix formulae, which you will find on the API.
Joined: Aug 21, 2004
I have tried the first two methods, rotating the graphics object, and the rotating the transform. I just tried the setToRotation and it yielded the same results as rotating the transform. Basically the image is rotating but it draws the rotated image over the original in the same frame, if that makes sense?
Does that work? That is the real question. "The proof of the pudding is in the eating."
If not, try passing the Graphics (or graphics2D) object from your paintComponent() method to your rotateImage() method. Or clone the Graphics2D object and pass it to the rotateImage() method.
If everything else works, and you are getting your image appearing twice: I presume you have super.paintComponent(); as the first line of your paintComponent() method? Try transforming the g2d object before you draw the image.