Search code examples
java3dimage-rotation

Is there any easy way to rotate an image about z axis using java without jumping into java 3d?


I want to rotate an image about the z axis using java.

I tried to search for ways to do that but it involves complex matrix manipulations and it works on 3d models and stuff. I will resort to that if there is no other way but would like to know if there are any other alternatives for this.

I simply need to rotate an image about z axis and nothing else.

EDIT

This is what I need exactly:

I have an image like this:

enter image description here

And I want to convert it to something of this sort:

enter image description here

I did this using processing. I need some way of doing this using java.


Solution

  • If you are referring to rotating an image during a Swing paint operation, then the correct way to do this is with an AffineTransform.

    Graphics2D graphic;
    graphic.drawRenderedImage(image, AffineTransform.getRotateInstance(Math.PI));
    

    Unfortunately AffineTransform does not support perspective transforms (by definition a transform is only Affine if parallel lines remain parallel). For perspective transforms you need to use the Java Advanced Imaging API which can be downloaded from Oracle's site. It has a PerspectiveTransform that does just what you want. Unfortunately JAI is not quite as straightforward to use as it is much more flexible.