?
Solved

Need to change the origin from Upper Left to Lower Left using AffineTransform in my paintComponent method

Posted on 2010-01-05
2
Medium Priority
?
414 Views
Last Modified: 2013-12-22
I have a class that extends JPanel that implements the paintComponent method.  In this method I am using the AffineTransform to draw and rotate Images using

public MyClass extends JPanel  {
  List<ImageClass>  imageList;
.......
   public void paintComponent (Graphics g)  {
       Graphics2D g2d = (Graphics2D) g;
       g.setColor(new Color(0xCDAA7D));
       g.fillRect(0, 0, this.getWidth(), this.getHeight());
       AffineTransform at = new AffineTransform();
       for (ImageClass image : imageList)  {
          at.translate(image.getX(), image.getY);
          at.rotate(image.getAngle(), image.getWidth() / 2, image.getHeight() / 2);
          g2d.drawImage(image, at, this);
          at.rotate(-image.getAngle(), image.getWidth() / 2, image.getHeight() / 2);
          at.translate(-image.getX(), -image.getY);
       }
}

The origin is in the upper left corner I need to change the origin to the lower left corner.
I tried using:

at.translate(0.0, sceneHeight);
at.scale(1.0, -1,0);

inserted before looping through my images to draw them but that did not work.
0
Comment
Question by:gdkinney_2
2 Comments
 
LVL 3

Accepted Solution

by:
softwarepearls_com earned 2000 total points
ID: 26190389
How about setting your Y-axis flipping transform on the Graphics2D context before entering the loop?
0
 

Author Comment

by:gdkinney_2
ID: 26212446
I think I have something that works to some degree at this point.  When I do the at.scale(1.0, -1,0); to flip and do a drawString call, the letters are upside down.  What can I do about that?

0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from http://seleniumhq.org Go to that link and select download selenium in the right hand column That will then direct you to their download page. From that p…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Suggested Courses
Course of the Month13 days, 19 hours left to enroll

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question