File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes AffineTransform make an image move Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "AffineTransform make an image move" Watch "AffineTransform make an image move" New topic
Author

AffineTransform make an image move

Mauricio Lopes
Greenhorn

Joined: Aug 04, 2009
Posts: 12
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
??
Craig Wood
Ranch Hand

Joined: Jan 14, 2004
Posts: 1535
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19697
    
  20

Mauricio Lopes wrote:??

http://faq.javaranch.com/java/PatienceIsAVirtue


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Cathy McDuff
Greenhorn

Joined: May 09, 2014
Posts: 18
Hi,

I just wanted to say thank you to Craig for posting that class, it's one of the few that actually makes sense and is easy to follow. Other classes using Affine Transform have been horrific to understand. So yeah, thank you very much, you've been a big help )
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39084
    
  23
Always start paintComponent with a super call and it has protected access, as in Craig Wood's post.
Don't use AffineTransforms on a Graphics object and then reuse the Graphics object. Take a defensive copy. What happens is that the calculations for the transform may be impossible to undo exactly, because of the imprecision of floating‑point arithmetic. Scale and translate usually can be undone and I have not had problems with rotate, but shear causes problems. The affine transforms also seem to be built into the Graphics2D object, so you have simpler ways to access them
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19697
    
  20

+1 on using Graphics.create. However, you should also dispose it manually:
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39084
    
  23
Rob Spoor wrote: . . . you should also dispose it manually . . .
I never knew that. Thank you.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39084
    
  23
More about Graphics#dispose here.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: AffineTransform make an image move