使用「仿射變換」我可以輕鬆旋轉imageA
。同樣,imageA
將與imageB
一起移動。但是,我似乎無法找到一種方法將imageA
旋轉後恢復到其原始位置。旋轉圖像(回到原始位置)
(我已經做了一些研究,一些網站,顯然是最好的方法是將圖像移回原來的位置,使它看起來像從一個錨點旋轉。)
繼承人到目前爲止我的代碼:
public void paintComponent(Graphics g) {
super.paintComponent(g);
AffineTransform af = new AffineTransform();
Graphics2D g2d = (Graphics2D) g;
af.translate(imageBx, imageBy); // moves ImageA to imageb's position
af.rotate(Math.toRadians(angle), imageB.getHeight(this)/2, imageB.getWidth(this)/2);
g2d.drawImage(imageA, af, null);
g2d.drawImage(imageB, imageBx, imageBy, null);
}
如果有人可以幫我搬imageA
回原來的位置(這是正確的imageB
)那會非常有幫助!
看看這個[示例](http://stackoverflow.com/a/3420651/230513)有幫助。 – trashgod
我看了一遍,但代碼旋轉了整個面板,我只想旋轉1個圖像(連接到另一個;類似於坦克和它的手臂)在一個固定的旋轉點上。 – Kenny