Forums Register Login

AffineTransform make an image move

+Pie Number of slices to send: Send
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 ?
+Pie Number of slices to send: Send
??
+Pie Number of slices to send: Send
+Pie Number of slices to send: Send
+Pie Number of slices to send: Send
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 )
1
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
+1 on using Graphics.create. However, you should also dispose it manually:
+Pie Number of slices to send: Send
 

Rob Spoor wrote: . . . you should also dispose it manually . . .

I never knew that. Thank you.
+Pie Number of slices to send: Send
More about Graphics#dispose here.
I was her plaything! And so was this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 5549 times.
Similar Threads
JPanel Form Problems
Wanted: Java2D example of zooming and panning with scroll bars
Resetting or Undoing AffineTransforms
Rotating a JWindow with multiple JPanels
Image Rotation
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 18, 2024 21:48:51.