Results 1 to 3 of 3
Thread: JPanel image rotating function
- 01-04-2012, 01:30 AM #1
Member
- Join Date
- Jan 2012
- Posts
- 28
- Rep Power
- 0
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(); }
Java Code:PictureRotation.createPicture(this);
-
Re: JPanel image rotating function
For one, your center of rotation will be off if the image has any eccentricity (if it's not close to being a square).
Similar Threads
-
Help with Image Rotating?
By Leospaceman in forum Java 2DReplies: 2Last Post: 05-31-2011, 02:48 PM -
Rotating Buffered Image distorts image
By VortexSpin in forum Java 2DReplies: 1Last Post: 02-13-2011, 05:54 AM -
rotating a rectangular image
By ighor10 in forum Java 2DReplies: 1Last Post: 10-24-2010, 07:22 PM -
Rotating an image
By lackofcolor in forum Java 2DReplies: 3Last Post: 02-27-2009, 11:54 PM -
Rotating Image?
By sciguy77 in forum Java AppletsReplies: 9Last Post: 02-17-2009, 01:47 AM
Bookmarks