Results 1 to 2 of 2

Thread: Image Rotation

  1. #1
    mix99 is offline Member
    Join Date
    Jan 2010
    Posts
    14
    Rep Power
    0

    Default Image Rotation

    Hi guys, I have the following code statement that draw an image on screen

    g2.drawImage(img, imgx, imgy, imgw, imgh, null);

    this statement work correctly.. Now, I want to rotate img object by 30 degrees, mantaining dimension. For this reason i found this solution

    Image img2 = img.getScaledInstance(imgw, imgh, Image.SCALE_DEFAULT);
    AffineTransform at = new AffineTransform();


    at.setToRotation(Math.toRadians(30), img2.getWidth(null)/2, img2.getHeight(null)/2);
    at.translate(imgx, imgy); (*)
    g2.drawImage(img2, at, null);

    It works, but the position of the image it's wrong because it's not the same of img. I think that statement (*) it's wrong... If i use at.setToTranslate, the rotation doesn't work...
    Have any idea?

    thank you in advance

  2. #2
    mix99 is offline Member
    Join Date
    Jan 2010
    Posts
    14
    Rep Power
    0

    Default

    this time i reply my answer myself...
    Following the correct solution

    Image img2 = deco.getScaledInstance(imgw, imgh, Image.SCALE_DEFAULT);
    AffineTransform at = new AffineTransform();


    at.translate(imgx, imgy);
    at.rotate(Math.toRadians(30), dec2.getWidth(null)/2, dec2.getHeight(null)/2);

    g2.drawImage(img2, at, null);

    The error was --> setToRotation...the correct solution is rotate...
    thank you again guys

Similar Threads

  1. Rotation & translation combined
    By ScottVal in forum Java 2D
    Replies: 4
    Last Post: 02-27-2011, 07:57 PM
  2. Need help with 2d Array rotation!
    By TrungTran in forum Advanced Java
    Replies: 1
    Last Post: 11-23-2008, 06:35 AM
  3. Log rotation in ubuntu
    By sarah11 in forum New To Java
    Replies: 0
    Last Post: 11-04-2008, 08:46 AM
  4. Rotation in java 3D
    By émilie- in forum Java Applets
    Replies: 0
    Last Post: 02-13-2008, 11:37 AM
  5. affineTransform rotation
    By MichYer in forum AWT / Swing
    Replies: 0
    Last Post: 07-18-2007, 09:55 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •