如何在Java中渲染倾斜的图像? [英] How to render tilted images in Java?
问题描述
我的问题是我有一个渲染图像的Java应用程序.现在,我想渲染一个倾斜的图像.
My problem is I have a Java application that renders an image. Now I want to render a tilted image.
一种简单的方法是先将图像倾斜,然后进行渲染,但我的目标是根据鼠标在窗口中的移动来倾斜图像.
One straightforward approach would be to have a tilted image and then render it, but my aim is to tilt the image according to the mouse movement in the window.
对此的一种可能的解决方案是在多个倾斜角度具有多个图像,并在鼠标移动时渲染它们,但是这种实现方式的精度受到限制,并不是我想要的.
One possible solution for this would be to have multiple images at various tilted angles and render them as the mouse moves, but such an implementation is limited in precision and not quite the thing I want.
有没有一种方法可以实时渲染倾斜的图像?
Is there a way to render the tilted image on the fly?
谢谢.
推荐答案
I think you need to look into AffineTransform it has a method for rotating a shape, as well as other transforms.
基本上:
AffineTransform at = AffineTransform.getTranslateInstance(width, height); //Create the AffineTransform instance
at.rotate(someRadianValue); // Apply the transforms you wish
g2.draw(at.createTransformedShape(myShape)); // Draw the transformed shape
这篇关于如何在Java中渲染倾斜的图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!