Results 1 to 3 of 3
  1. #1
    antnas is offline Member
    Join Date
    Oct 2012
    Posts
    15
    Rep Power
    0

    Default How do I flip this image?

    I made code so that I can copy a smaller picture into a bigger picture which is working but I need to add code to make it flip 180 degrees and I do not know how to go about that.
    This is my code so far it picks up every pixel in the picture.
    Java Code:
    public void copyInto(int xWhere, int yWhere, Picture flower)
      {
        for(int x = 0; x < flower.getWidth(); x++)
        {
          for(int y = 0; y < flower.getHeight(); y++)
          {
            int red;
            int green;
            int blue;
            red = flower.getPixel(x,y).getRed();
            green = flower.getPixel(x,y).getGreen();
            blue = flower.getPixel(x,y).getBlue();
            this.getPixel(xWhere + x, yWhere + y).setColor(new Color(red, green, blue) );
          }
        }
      }

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

    Default Re: How do I flip this image?

    The solution is in the last line of your code: now it puts a pixel at (x,y) (flower coordinates) at (xWhere+x, yWhere+y) (image coordinates). If you stick it at position (xWhere+flower.getWidth()-1-x, yWhere+y) you have flipped your flower over a vertical axis; flipping over a horizontal axis is left as an exercise for the reader ;-)

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    antnas is offline Member
    Join Date
    Oct 2012
    Posts
    15
    Rep Power
    0

    Default Re: How do I flip this image?

    This helped a bunch! Thank you!

Similar Threads

  1. Flip int value(1234 becomes 4321)
    By Pojahn_M in forum New To Java
    Replies: 2
    Last Post: 09-27-2012, 11:47 PM
  2. Flip Pictures on DrJava
    By siddanth1 in forum New To Java
    Replies: 2
    Last Post: 02-10-2012, 02:08 AM
  3. coin flip program
    By chandrasekhar.melam in forum New To Java
    Replies: 5
    Last Post: 09-26-2011, 05:30 PM
  4. Othello/Reversi flip checkers
    By chielt in forum Java Applets
    Replies: 10
    Last Post: 01-02-2010, 11:25 PM
  5. Random coin flip application
    By Boomer1 in forum New To Java
    Replies: 8
    Last Post: 12-18-2009, 02:57 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
  •