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 7162303
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T13:42:45+00:00 2026-05-28T13:42:45+00:00

I am trying to rotate a png that is loaded in Java. The problem

  • 0

I am trying to rotate a png that is loaded in Java. The problem I have is that when I rotate the image, it also appears to also mess up the position of the image. I am rotating a 60×60 image so I would assume that rotating it would not move the image. Is there a way I can either rotate the image without moving it or a way to set the coordinates of an affine transformation?

        AffineTransform identity = new AffineTransform();
        gr.setColor(Color.red);

        gr.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY );

        AffineTransform trans = new AffineTransform();
        trans.setTransform(identity);
        trans.rotate( -Math.toRadians(15) );
        trans.translate(-25, 220);

        gr.drawImage(body.getImage(), 0, 200, null);
        gr.drawImage(gun.getImage(), trans, this);
  • 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-05-28T13:42:46+00:00Added an answer on May 28, 2026 at 1:42 pm

    AffineTransform instances can be concatenated (added together) using concatenate(AffineTransform). The General way to rotate an image would be to.

    • Move the center of the image to the origin (getTranslateInstance()).
    • Rotate the image (getRotateInstance()).
    • Move it back to the original co-ordinates (getTranslateInstance()).

    In fact, look to the methods for

    • getRotateInstance(double theta,
      double anchorx,
      double anchory)

      Returns a transform that rotates coordinates around an anchor point. This operation is equivalent to translating the coordinates so that the anchor point is at the origin (S1), then rotating them about the new origin (S2), and finally translating so that the intermediate origin is restored to the coordinates of the original anchor point (S3).
    • getRotateInstance(double vecx,
      double vecy,
      double anchorx,
      double anchory)

      Returns a transform that rotates coordinates around an anchor point accordinate (sic) to a rotation vector. All coordinates rotate about the specified anchor coordinates by the same amount. The amount of rotation is such that coordinates along the former positive X axis will subsequently align with the vector pointing from the origin to the specified vector coordinates. If both vecx and vecy are 0.0, an identity transform is returned. This operation is equivalent to calling: …

    Thanks to Donal Fellows for prompting me to RTM.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to rotate an image in OpenCV. I've used this code that
I am trying to rotate an image in Java, but when I do the
Okay I'm trying to rotate a Java Polygon based on it's original position of
I am trying to rotate an image using jquery that will rotate on multiple
I am trying to rotate image that is placed partly on the screen using
I'm trying to set up a UITableViewCell that can have an image in the
Basically what I'm trying to do is have a picture rotate using mouse events.
I am trying to change my Sprite anchor point so that I can rotate
When I have a QUAD at a certain position, how can I rotate it
I am trying to rotate an image with Jquery rotateAnimation and trying to add

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.