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

半腔热情 提交于 2019-12-25 02:49:08

问题


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:

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

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


回答1:


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.



来源:https://stackoverflow.com/questions/30587938/is-there-any-easy-way-to-rotate-an-image-about-z-axis-using-java-without-jumping

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!