简体   繁体   中英

How to rotate the Image along y-axis?

The code i tried is rotating the image but i want to rotate the image vertically like rotating earth at 360 degrees with 0 inclination

The code i tried is

 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/ Reference link of the RotatedIcon class i used. As Explained am able to rotate image but that is not vertically.

If you only have a flat 2D image of the world then then best you might be able to do is use the Marquee Panel .

The Marquee Panel will allow you to scroll the image and you can set it to wrap when it reaches the end. You won't get a 3D effect buy you will scroll around the world with a flat 2D image.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM