Results 1 to 3 of 3
  1. #1
    anoorally is offline Member
    Join Date
    Jan 2012
    Posts
    28
    Rep Power
    0

    Default JPanel image rotating function

    In a generic class i created the following function:

    Java Code:
            public static void createPicture(JFrame f) throws Exception {
        	    final BufferedImage bi = ImageIO.read(new File("picture.png"));
        	    JPanel newPanel = new JPanel() {
    
                    @Override
                    public Dimension getPreferredSize() {
                        return new Dimension(bi.getWidth(), bi.getHeight());
                    }
    
                    @Override
                    protected void paintComponent(Graphics g) {
                        super.paintComponent(g);
                        Graphics2D g2 = (Graphics2D) g;
                        g2.rotate(Math.toRadians(90), bi.getWidth() / 2, bi.getHeight() / 2);
                        //g2.rotate(Math.toRadians(0),bi.getWidth(), bi.getHeight()-bi.getWidth());
                        g2.drawImage(bi, 0, 0, null);
                    }
                };
        	f.add(newPanel);
            f.setSize(f.getPreferredSize().height, f.getPreferredSize().width);
            f.repaint();
        }
    and then called the function in another class called GUI which has a the actual user interface through the following code, at the click of a jbutton:
    Java Code:
    PictureRotation.createPicture(this);
    Nothing is displayed on the JFrame, anything wrong with the codes?

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

Similar Threads

  1. Help with Image Rotating?
    By Leospaceman in forum Java 2D
    Replies: 2
    Last Post: 05-31-2011, 03:48 PM
  2. Rotating Buffered Image distorts image
    By VortexSpin in forum Java 2D
    Replies: 1
    Last Post: 02-13-2011, 06:54 AM
  3. rotating a rectangular image
    By ighor10 in forum Java 2D
    Replies: 1
    Last Post: 10-24-2010, 08:22 PM
  4. Rotating an image
    By lackofcolor in forum Java 2D
    Replies: 3
    Last Post: 02-28-2009, 12:54 AM
  5. Rotating Image?
    By sciguy77 in forum Java Applets
    Replies: 9
    Last Post: 02-17-2009, 02:47 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •