Results 1 to 5 of 5
  1. #1
    NoobieCode is offline Senior Member
    Join Date
    Mar 2013
    Posts
    123
    Rep Power
    0

    Default Rotation 90 degrees to right Help

    Hello
    I need help rotating a pic 90 degrees to the right

    Java Code:
       Photograph rotated_photo = new Photograph(photo.getWidth(), photo.getHeight());
              
              for (int col = 0; col < photo.getHeight(); col ++){
            	  for (int row = 0; row < photo.getWidth(); row ++){
            		  
            		  Pixel p = photo.getPixel(row, col);
            		  rotated_photo.setPixel(???, ???, p);       //Please give me hint on how to do this
    }
    }
    
    return rotated_photo;

  2. #2
    wsaryada is offline Senior Member
    Join Date
    Jun 2007
    Location
    Bali, Indonesia
    Posts
    758
    Rep Power
    8

    Default Re: Rotation 90 degrees to right Help

    Part of what library / API is the Photograph class?

  3. #3
    NoobieCode is offline Senior Member
    Join Date
    Mar 2013
    Posts
    123
    Rep Power
    0

    Default Re: Rotation 90 degrees to right Help

    Quote Originally Posted by wsaryada View Post
    Part of what library / API is the Photograph class?
    The Photograph and Pixel Class is a custom classes created by my professor.
    -------------------------------------------------------------------

  4. #4
    NoobieCode is offline Senior Member
    Join Date
    Mar 2013
    Posts
    123
    Rep Power
    0

    Default Re: Rotation 90 degrees to right Help

    I need help on the math. I'm not getting it.

    My objective is to take an image and rotate 90 degrees to the right.

    So given an image with letters as pixels:


    abcd
    efgh
    i j k l
    mnop

    (becomes this after rotation)

    m i e a
    n j f b
    o k g c
    p l h d

    ----

    So I create a new photo image

    Create a nested for loop to go through each row and col

    Find the pixel in each row and column

    and the set the pixel to the new photo



    ------

    so I have (psuedo-code)


    Photograph rotate = new Photo (getwidth, getheight);

    for ( row = 0; row < width ; row ++)
    for (col = 0; col < height ; col ++0

    get pixel (row, col)

    rotate.setPixel ( ????? , ???? , pixel)

    ----


    I need help on what to fill in for the "????"
    I drew it out and I know when rotated, row becomes col and vise versa...
    Im just not getting it.

  5. #5
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,453
    Blog Entries
    7
    Rep Power
    20

    Default Re: Rotation 90 degrees to right Help

    Suppose there are R rows and C columns; for matrix coordinate [y,x] (row, column) the rotated coordinates are [x, R-y-1].

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. Help to rotate a pic 180 degrees (upside down)
    By Track13 in forum New To Java
    Replies: 7
    Last Post: 11-16-2012, 04:27 AM
  2. Math.atan --- To Degrees Help
    By GregoryNeal in forum New To Java
    Replies: 1
    Last Post: 03-07-2012, 06:54 AM
  3. Rotating an image 90 Degrees
    By cvillejin in forum New To Java
    Replies: 4
    Last Post: 04-03-2011, 07:56 PM
  4. Radians to Degrees issue?
    By Joey Gobert in forum Advanced Java
    Replies: 5
    Last Post: 12-15-2010, 08:41 PM
  5. [j2me] sprite rotation with degrees
    By Rooneyz in forum CLDC and MIDP
    Replies: 0
    Last Post: 07-06-2009, 03:40 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
  •