Results 1 to 3 of 3
  1. #1
    Addez is offline Senior Member
    Join Date
    Aug 2009
    Posts
    294
    Rep Power
    0

    Default This method does not rotate the bufferedImage around its center :(

    Hai!
    I got this method from my old codes, I assumed it rotated the image around its center.
    But it really dont..
    The image doesnt move, but the car does :(
    How come?

    Here my method:
    PHP Code:
     public static BufferedImage rotateImg(BufferedImage bufferedImage,double radians){
            double radians2 = radians*Math.PI/180;
            radians = (int)radians2;
    
    
            AffineTransform tx = new AffineTransform();
            tx.rotate(radians2, bufferedImage.getWidth()/2, bufferedImage.getHeight()/2);
            AffineTransformOp op = new AffineTransformOp(tx, AffineTransformOp.TYPE_BILINEAR);
            bufferedImage = op.filter(bufferedImage, null);
            return bufferedImage;
        }

  2. #2
    Addez is offline Senior Member
    Join Date
    Aug 2009
    Posts
    294
    Rep Power
    0

    Default

    I think the problem might be caused because the image seem to change size after rotating..
    Its a low probebility that that is the cause, but still,
    How can I then rotate the image without changing the image size?

  3. #3
    Addez is offline Senior Member
    Join Date
    Aug 2009
    Posts
    294
    Rep Power
    0

    Default

    Yays, I almoste fixed it!
    I made it so that the img size doesnt change, but one problem
    got created meanwhile:
    The pictures colors are messed up!

    Idk why, maybe inverted or somehting.. Idk but why does this makes the picture change color (heres the method):
    PHP Code:
    public static BufferedImage rotateImg(BufferedImage bufferedImage,double radians){
            double radians2 = radians*Math.PI/180;
            radians = (int)radians2;
    
            BufferedImage imgDest = new BufferedImage(bufferedImage.getWidth(),bufferedImage.getHeight(), BufferedImage.TYPE_INT_ARGB); 
            AffineTransform tx = new AffineTransform();
            tx.rotate(radians2, bufferedImage.getWidth()/2, bufferedImage.getHeight()/2);
            AffineTransformOp op = new AffineTransformOp(tx, AffineTransformOp.TYPE_BILINEAR);
            bufferedImage = op.filter(bufferedImage, imgDest);
            return imgDest;
        }

Similar Threads

  1. How to rotate an image
    By ChipChamp in forum New To Java
    Replies: 4
    Last Post: 06-20-2012, 08:22 PM
  2. Image rotate
    By Micromani in forum AWT / Swing
    Replies: 0
    Last Post: 03-17-2010, 02:33 PM
  3. My rotate 2d pos method isnt working correctly..
    By Addez in forum New To Java
    Replies: 5
    Last Post: 12-01-2009, 10:04 AM
  4. Rotate Image!
    By Moncleared in forum AWT / Swing
    Replies: 1
    Last Post: 02-11-2009, 06:22 PM
  5. JFrame rotate
    By etheralthougt in forum AWT / Swing
    Replies: 1
    Last Post: 10-24-2008, 07:03 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
  •