有没有什么简单的方法可以使用java围绕z轴旋转图像而不跳入java 3d?
我想使用 java 围绕 z 轴旋转图像.
I want to rotate an image about the z axis using java.
我试图寻找方法来做到这一点,但它涉及复杂的矩阵操作,并且适用于 3d 模型和其他东西.如果没有其他方法,我会求助于该方法,但我想知道是否还有其他选择.
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.
我只需要围绕 z 轴旋转图像即可.
I simply need to rotate an image about z axis and nothing else.
编辑
这正是我需要的:
我有一个这样的图像:
我想把它转换成这样的:
And I want to convert it to something of this sort:
我使用处理来做到这一点.我需要一些使用 java 来做到这一点的方法.
I did this using processing. I need some way of doing this using java.
如果您指的是在 Swing paint
操作期间旋转图像,那么正确的方法是使用 仿射变换
.
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));
不幸的是,AffineTransform
不支持透视变换(根据定义,如果平行线保持平行,变换只是仿射).对于透视变换,您需要使用 Java Advanced Imaging API,它可以从 Oracle 的站点下载.它有一个 PerspectiveTransform
可以满足您的需求.不幸的是,JAI 使用起来并不那么简单,因为它更加灵活.
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.