A friendly place for programming greenhorns!
Big Moose Saloon
Search
|
Java FAQ
|
Recent Topics
Register / Login
JavaRanch
»
Java Forums
»
Java
»
Swing / AWT / SWT
Author
AffineTransform make an image move
Mauricio Lopes
Greenhorn
Joined: Aug 04, 2009
Posts: 12
posted
Aug 04, 2009 21:26:25
0
I've been trying to make an image rotate in a panel. I did it. But also i want the image to make a translation.
Here is the code i tryed at paintComponent() :
//////////////////////////
Graphics2D g2 = (Graphics2D) g ;
AffineTransform
at = new
AffineTransform
() ;
// at.rotate ( angle in radians ) ;
at.rotate( this.getAngulo(1, 1) ) ;
g2.drawImage(imgemFlecha, at, this);
/////////////////////////////
I cant change image x,y doing this drawImage(). I want to make that change.
Any suggestions ?
Mauricio Lopes
Greenhorn
Joined: Aug 04, 2009
Posts: 12
posted
Aug 05, 2009 09:58:33
0
??
Craig Wood
Ranch Hand
Joined: Jan 14, 2004
Posts: 1535
posted
Aug 05, 2009 23:50:13
0
import java.awt.*; import java.awt.geom.AffineTransform; import java.awt.image.BufferedImage; import java.io.*; import javax.swing.*; public class Mobility extends JPanel { BufferedImage image; public Mobility(BufferedImage image) { this.image = image; } protected void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2 = (Graphics2D)g; int iw = image.getWidth(); int ih = image.getHeight(); double x = 50; double y = 50; AffineTransform at = AffineTransform.getTranslateInstance(x, y); at.rotate(Math.PI/6, iw/2, ih/2); g2.drawRenderedImage(image, at); x = 150; y = 150; at.setToTranslation(x, y); at.rotate(Math.PI/4, iw/2, ih/2); g2.drawRenderedImage(image, at); x = 250; y = 250; at.setToTranslation(x, y); at.rotate(Math.PI/3, iw/2, ih/2); g2.drawRenderedImage(image, at); } public static void main(String[] args) throws IOException { File file = new File("images/geek/geek-----.gif"); BufferedImage image = javax.imageio.ImageIO.read(file); JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.add(new Mobility(image)); f.setSize(400,400); f.setLocation(100,100); f.setVisible(true); } }
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19216
I like...
posted
Aug 06, 2009 01:19:04
0
Mauricio Lopes wrote:
??
http://faq.javaranch.com/java/PatienceIsAVirtue
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions
How To Answer Questions
I agree. Here's the link:
http://aspose.com/file-tools
subject: AffineTransform make an image move
Similar Threads
Rotating a JWindow with multiple JPanels
JPanel Form Problems
Wanted: Java2D example of zooming and panning with scroll bars
Resetting or Undoing AffineTransforms
Image Rotation
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter