我尝试的代码是旋转图像,但我想垂直旋转图像,就像旋转地球一样,以 0 倾角 360 度旋转
我尝试过的代码是
public class MainClass extends JPanel {
static ImageIcon icon = null;
static RotatedIcon rotate = null;
static JLabel label = null;
public MainClass() {
try {
BufferedImage wPic = ImageIO.read(this.getClass().getResource(
"globe.png"));
icon = new ImageIcon(wPic);
rotate = new RotatedIcon(icon, 180);
label = new JLabel(rotate);
} catch (Exception e) {
System.out.println("raise exception");
}
}
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
label.repaint();
}
public static void main(String[] args) throws IOException,
InterruptedException {
MainClass mainClass = new MainClass();
JFrame frame = new JFrame();
mainClass.add(label);
frame.add(mainClass);
frame.setSize(500, 500);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
ActionListener taskPerformer = new ActionListener() {
int degree = 360;
public void actionPerformed(ActionEvent evt) {
rotate.setDegrees(degree);
degree = degree + 90;
label.repaint();
mainClass.repaint();
}
};
Timer timer = new Timer(1000, taskPerformer);
// timer.setRepeats(false);
timer.start();
Thread.sleep(5000);
}
}
https://tips4java.wordpress.com/2009/04/06/rotated-icon/我使用的 RotatedIcon 类的引用链接。 正如所解释的,我能够旋转图像,但不是垂直旋转。
最佳答案
如果您只有世界的平面 2D 图像,那么您最好的办法就是使用 Marquee Panel .
选框面板将允许您滚动图像,并且您可以将其设置为在到达末尾时换行。您不会获得 3D 效果,而是通过平面 2D 图像滚动环游世界。
关于java - 如何沿y轴旋转图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44892007/