Link to home
Start Free TrialLog in
Avatar of tom1234
tom1234Flag for Korea, Republic of

asked on

why using translate twice?

 GC gc = e.gc;
  gc.setAdvanced(true);
 
  Bounds b = image.getBounds();

  Transform transform = new Transform(display);
  // The rotation point is the center of the image
  transform.translate(50 + b.width/2, 50 + b.height/2);
  // Rotate
  transform.rotate(45);
  // Back to the orginal coordinate system
  transform.translate(-50 - b.width/2, -50 - b.height/2);
  gc.setTransform(transform);
  gc.drawImage(image, 50, 50);
  transform.dispose();

above the code, a translate method is used twice . why is it used twice??
Avatar of Mick Barry
Mick Barry
Flag of Australia image

so that it is rotated on the centre of the image
without the translations it would rotate arounf the top left corner of image
Avatar of tom1234

ASKER

hm...
I can not understand..

please , tell me more detaily?
ASKER CERTIFIED SOLUTION
Avatar of Mick Barry
Mick Barry
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of tom1234

ASKER

thanks
Avatar of tom1234

ASKER

can you tell me the meaning of 'translate method'?
shifts points a fixed number of pixels in x and y direction