简体   繁体   English

在Java中旋转图片?

[英]Rotate an image in java?

I have been trying to rotate an image on a certain degree, and still remain on the same position. 我一直在尝试将图像旋转到一定程度,但仍然保持在同一位置。 I have tried g.rotate, but it just rotate around a center, and it does not keep the same position as before. 我试过了g.rotate,但是它只是绕中心旋转,并且它没有像以前那样保持相同的位置。 Any example to understand how it works would be great! 任何了解它如何工作的示例都将很棒!

When rotation occurs it happens relative to the origin of the screen (x=0, y=0). 发生旋转时,它相对于屏幕的原点(x = 0,y = 0)发生。 To make an image rotate relative to its center point you must first translate the image to the origin, perform the rotation, and then translate it back. 要使图像相对于其中心点旋转,必须首先将图像平移到原点,执行旋转,然后再平移回原点。

If you are using Graphics2D, reading this article may prove useful: 如果您使用的是Graphics2D,那么阅读本文可能会很有用:

Rotate an Image using Graphics2D and AffineTransform 使用Graphics2D和AffineTransform旋转图像

This example offers a bit more detail: 这个例子提供了更多细节:

Rotate an image - in more detail :) 旋转图像-更详细:)

I hope you find the two helpful. 希望对您有帮助。 Ultimately it may help to post some of your code in the future for a more relevant answer. 最终,它可能有助于将来发布一些代码以获得更相关的答案。

Good luck! 祝好运!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM