Results 1 to 2 of 2
  1. #1
    ighor10 is offline Member
    Join Date
    Mar 2010
    Posts
    9
    Rep Power
    0

    Default rotating a rectangular image

    Hello,

    I am trying to rotate a buffered image.

    the problem is that my image is a rectangular image, like 60x40 px.
    and the rotation work to square images.

    here is my code


    private BufferedImage rotate(BufferedImage bufferedImage, double radians) {
    AffineTransform at = new AffineTransform();
    at.rotate(radians, bufferedImage.getWidth() / 2, bufferedImage.getHeight() / 2);
    AffineTransformOp ato = new AffineTransformOp(at, AffineTransformOp.TYPE_BILINEAR);
    return ato.filter(bufferedImage, null);
    }




    ...
    rotatedImage = rotate(bufferedImage, 2);
    this.setSize(rotatedImage.getWidth(), rotatedImage.getHeight());
    this.setIcon(new ImageIcon(rotatedImage));
    ...



    I dont know how to fix this.


    Thanks for help.

  2. #2
    Horcrux7 is offline Member
    Join Date
    Sep 2010
    Posts
    33
    Rep Power
    0

    Default

    The rotation around the center point is simple but work only good with square. It is not a square then it is better to rotate on the 0,0 point and then move. Depending if you rotate left or right you must move width down or the height to right. Hold a paper on the 0.0 position and rotate it. Then you see how must move it that the left/top corner is on the 0,0 position.
    Volker Berlin
    www.inetsoftware.de

Similar Threads

  1. Rotating image based on the direction of a line
    By YellowPainting in forum New To Java
    Replies: 4
    Last Post: 08-06-2010, 09:32 AM
  2. Replies: 3
    Last Post: 06-16-2010, 11:27 PM
  3. Rotating an image
    By lackofcolor in forum Java 2D
    Replies: 3
    Last Post: 02-28-2009, 12:54 AM
  4. Rotating Image?
    By sciguy77 in forum Java Applets
    Replies: 9
    Last Post: 02-17-2009, 02:47 AM
  5. Rotating and flipping an image in SWT
    By Java Tip in forum SWT Tips
    Replies: 0
    Last Post: 07-02-2008, 09:01 PM

Posting Permissions

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