Results 1 to 10 of 10
  1. #1
    jsobel is offline Member
    Join Date
    Apr 2012
    Posts
    68
    Rep Power
    0

    Default Rotating Buffered Image

    Ok i've been searching on google for the past half hour looking for a way to rotate a buffered image by x amount of derees in a method that looks something like this

    Java Code:
    public static BufferedImage rotate(BufferedImage a,int rotation)
    {
    return //the rotated BufferedImage
    }
    btw i dont want to draw it rotated i need to rotate it seperately so i can save it rotated

  2. #2
    jsobel is offline Member
    Join Date
    Apr 2012
    Posts
    68
    Rep Power
    0

    Default Re: Rotating Buffered Image

    i found this on the web but it cuts off some of the picture when rotated
    Java Code:
            public static BufferedImage rotate(BufferedImage img, int rotation) 
            {
    	int w = img.getWidth();  
    	int h = img.getHeight();  
    	BufferedImage newImage = new BufferedImage(width, height, img.getType());
            Graphics2D g2 = newImage.createGraphics();
            g2.rotate(Math.toRadians(rotation), w/2, h/2);  
            g2.drawImage(img,null,0,0);
    	return newImage;  
    	}
    Last edited by jsobel; 09-29-2012 at 05:36 PM. Reason: Edit

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is online now Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,453
    Rep Power
    20

    Default Re: Rotating Buffered Image

    Moved from Advanced Java. Please take the effort to find a suitable section for your questions. Moreover, a simple application of available API can in no way be considered an advanced question.

    Copying code (which may or may not be correct) and trying to use it without understanding it doesn't further your knowledge. Sketch out your original image and the 'rotated' newImage on paper and you should be immediately able to spot what's wrong.

    But, where do the first two parameters to the constructor of newImage come from?

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  4. #4
    jsobel is offline Member
    Join Date
    Apr 2012
    Posts
    68
    Rep Power
    0

    Default Re: Rotating Buffered Image

    I have an image i load into a class in the classes main method using the imageio class then i call the rotate method on it and then i save it to a file and part of the image is missing it has something to do with the size of the new image

  5. #5
    jsobel is offline Member
    Join Date
    Apr 2012
    Posts
    68
    Rep Power
    0

    Default Re: Rotating Buffered Image

    Rotating Buffered Image-duke-real.gifRotating Buffered Image-img-rotate.jpg
    this is what i mean by being cut off when turned

  6. #6
    DarrylBurke's Avatar
    DarrylBurke is online now Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,453
    Rep Power
    20

    Default Re: Rotating Buffered Image

    Quote Originally Posted by jsobel View Post
    it has something to do with the size of the new image
    Si fix that! Your code specifies the size when constructing the BufferedImage. Do the math and specify the correct size.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  7. #7
    jsobel is offline Member
    Join Date
    Apr 2012
    Posts
    68
    Rep Power
    0

    Default Re: Rotating Buffered Image

    yeah well even when i do that the image gets cut off because the graphics size doesn't change

  8. #8
    DarrylBurke's Avatar
    DarrylBurke is online now Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,453
    Rep Power
    20

    Default Re: Rotating Buffered Image

    Graphics doesn't have a size.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  9. #9
    jsobel is offline Member
    Join Date
    Apr 2012
    Posts
    68
    Rep Power
    0

    Default Re: Rotating Buffered Image

    I dont know but when i rotate an image and put it into a larger image it still gets cut off

  10. #10
    DarrylBurke's Avatar
    DarrylBurke is online now Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,453
    Rep Power
    20

    Default Re: Rotating Buffered Image

    To get better help sooner, post a SSCCE that clearly demonstrates your problem.

    db
    Last edited by DarrylBurke; 11-13-2012 at 03:39 PM.
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Drawing on and rotating buffered Image
    By NutterzUK in forum AWT / Swing
    Replies: 1
    Last Post: 12-09-2011, 05:55 AM
  2. Help with Image Rotating?
    By Leospaceman in forum Java 2D
    Replies: 2
    Last Post: 05-31-2011, 03:48 PM
  3. Volatile image vs buffered image
    By trishtren in forum Java 2D
    Replies: 0
    Last Post: 04-18-2011, 12:31 AM
  4. Rotating Buffered Image distorts image
    By VortexSpin in forum Java 2D
    Replies: 1
    Last Post: 02-13-2011, 06:54 AM
  5. Rotating an image
    By lackofcolor in forum Java 2D
    Replies: 3
    Last Post: 02-28-2009, 12:54 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
  •