[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 460
  • Last Modified:

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??
0
gamjaradio
Asked:
gamjaradio
  • 3
  • 3
1 Solution
 
objectsCommented:
so that it is rotated on the centre of the image
without the translations it would rotate arounf the top left corner of image
0
 
gamjaradioAuthor Commented:
hm...
I can not understand..

please , tell me more detaily?
0
 
objectsCommented:
1. translates to the centre of image
2. rotate image
3. translate back to top left corner

try it without the translates to see the difference
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
gamjaradioAuthor Commented:
thanks
0
 
gamjaradioAuthor Commented:
can you tell me the meaning of 'translate method'?
0
 
objectsCommented:
shifts points a fixed number of pixels in x and y direction
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now