[英]How to rotate the Image along y-axis?
我尝试过的代码正在旋转图像,但是我想垂直旋转图像,就像以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);
}
}
我使用的RotatedIcon类的https://tips4java.wordpress.com/2009/04/06/rotated-icon/参考链接。 正如解释的那样,它能够旋转图像,但是不能垂直旋转。
如果您只有一个平面的2D图像,那么最好的选择就是使用“ 字幕”面板 。
“ Marquee Panel
将允许您滚动图像,并且可以将其设置为在结束时自动换行。 购买3D效果后,您将获得带有平面2D图像的环球滚动。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.