Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8238693
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T19:54:01+00:00 2026-06-07T19:54:01+00:00

I am using Java’s Graphics2D to draw on a component using AffineTransform’s to manipulate

  • 0

I am using Java’s Graphics2D to draw on a component using AffineTransform’s to manipulate my drawing.
Graphics2D offers an method transform for this, which takes an AffineTransform.

Sometimes I need to manipulate a point manually without using the builtin-transformation.
But when I try to transform a point using the same transformation I gave to Graphics2D.transform sometimes the resulting point is not the same.

The following code reproduces the problem (It’s Scala code, but I think you can imagine the Java code.):

   var transformationMatrix = new AffineTransform()
   /*
    * transformationMatrix is modified throughout the program
    * ...
    */
   override def paintComponent(g: Graphics2D) = {
      super.paintComponent(g)
      /* 1. transform using graphics transform */
      g.transform(transformationMatrix)
      g.setColor(Color.RED)
      g.fill(new Rectangle(0, 0, 1, 1))
      /* 2. transform point manually */
      g.setTransform(new AffineTransform) // reset transformation to standard
      val p0 = new Point(0, 0)
      val pDest = new Point()
      transformationMatrix.transform(p0, pDest)
      g.setColor(Color.BLUE)
      g.fill(new Rectangle(pDest.x, pDest.y, 1, 1)
   }

Expected behaviour

The blue rectangle (manually calculated) overdraws the red one (calculated by transform).

Experienced behaviour

The blue rectangle has an offset of 1

I admit that my transformationMatrix is not really integer, but that should’nt be the problem, should it?

   affineTransform = 1.1, 0.0, 520.55
                     0.0, 1.1, 182.54999999999995
                     0.0, 0.0,    1.0

Is this a bug or am I missing some deep insight?

Edit: You can reproduce the bug, if you set transformationMatrix to

transformationMatrix = new AffineTransform(1.1, 0.0, 0.0, 1.1, 521.55, 183.54999999999995)

at the beginning of paintComponent. Please note, that g is of type Graphics2D.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T19:54:02+00:00Added an answer on June 7, 2026 at 7:54 pm

    Well, you are doing two different things.

    In (1) you are subjecting a shape (and it is irrelevant that it is Rectangle and not Rectangle2D.Double) to a transform that yields fractional coordinates. It only is painted aliased, because you haven’t set specific rendering hints (RenderingHints.KEY_ANTIALIASING -> RenderingHints.VALUE_ANTIALIAS_ON, and RenderingHints.KEY_STROKE_CONTROL -> RenderingHints.VALUE_STROKE_PURE).

    In (2) you are subjecting a point to the transform, and coerce it into aliased coordinates (Point instead of Point2D.Double). Then successively construct a rectangle from that point.

    Clearly there may be very different things happening under the hood, and I wouldn’t expect at all that transforming into an integer point versus painting floating point shapes in an aliasing graphics context yield the same results.

    (Without testing) I would guess that a valid equivalent statement for (1) would be

    g.fill(transformationMatrix.createTransformedShape(new Rectangle(0, 0, 1, 1)))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using Java, I have a method which I'm calling with method.invoke that returns a
Using java I am trying to develop a method using recursion to analyze a
(Using Java) I am implementing a generic class which is a B-Tree. When the
Using Java sockets, I made a simple server. This works because it sends data
Using Java Generics, I tried to implement a generic console input method. public static
Using java.util.logging.Logger to output some log to the console just like this: public static
Using Java, I have a class which retrieves a webpage as a byte array.
Using Java which is the best way to merge two arrays of class based
Using Java is it possible to capture the speaker output? This output is not
Using JAVA framework i want to achieve the following task. hot code(jar) deployment which

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.