[英]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.