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

Posted on 2010-01-05
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.
Question by:gdkinney_2
    LVL 3

    Accepted Solution

    How about setting your Y-axis flipping transform on the Graphics2D context before entering the loop?

    Author Comment

    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?


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Find Ransomware Secrets With All-Source Analysis

    Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

    Suggested Solutions

    Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
    Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
    This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
    THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.

    794 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

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now