Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Vertical mirror help

  1. #1
    Junior Member
    Join Date
    Feb 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Vertical mirror help

    I'm new to Java and I really need some help! I need to write a method to mirror the left half of a picture to the right half of the picture motorcycle.jpg (see attachment for example). I have a method, but it flips the image and copies it to a new picture. I need the method to take half of the image and mirror it over the other half of the image. Please help!

     
    public Picture flip() {
        Pixel currPixel = null;
        Pixel targetPixel = null;
        Picture target = 
          new Picture(FileChooser.pickAFile());
     
        for (int srcX = 0, trgX = getWidth()-1; 
             srcX < getWidth();
             srcX++, trgX--) {
          for (int srcY = 0, trgY = 0; 
               srcY < getHeight();
               srcY++, trgY++) {
     
            // get the current pixel
            currPixel = this.getPixel(srcX,srcY);
            targetPixel = target.getPixel(trgX,trgY);
     
            // copy the color of currPixel into target
            targetPixel.setColor(currPixel.getColor());
          }
        }
        return target;
      }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    20,973
    Thanks
    51
    Thanked 2,269 Times in 2,241 Posts

    Default Re: Vertical mirror help

    What steps or algorithm mus the code do to "mirror" an image?
    Can you describe the steps the code must do to move the pixels to get the desired output?
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. arranging components in a vertical manner in a jpanel?
    By buencamino in forum AWT / Java Swing
    Replies: 2
    Last Post: July 18th, 2012, 09:33 PM
  2. Program to launch and mirror another program
    By hayate in forum Java Theory & Questions
    Replies: 13
    Last Post: March 8th, 2012, 11:47 PM
  3. 1 vertical scroll bar fro 2 jtextareas
    By fortune2k in forum AWT / Java Swing
    Replies: 8
    Last Post: March 4th, 2011, 01:04 PM

Tags for this Thread