Results 1 to 2 of 2
  1. #1
    tecnicamente is offline Member
    Join Date
    May 2011
    Rep Power

    Default How to Copy and Flip a Picture Horizontally

    I am working on a class that flips a picture on its horizontal axis.
    I know that I have to copy the picture and then use the copy to help flip the picture, however I am unsure of what is going wrong.
    Any help would be much appreciated.

    class FlipHorizontally implements ActionListener {
    public void actionPerformed (ActionEvent e) {
    int imageWidth = picture.getWidth();
    int imageHeight = picture.getHeight();
    Picture copy = new Picture(picture.getWidth(), picture.getHeight());
    copy.drawPicture(0,0, picture);
    for (int x = 0; x < picture.getWidth(); x++) {
    for (int y = 0; y < picture.getHeight(); y++) {
    int red = copy.getPixelRed(x,y);
    int green = copy.getPixelGreen(x,y);
    int blue = copy.getPixelBlue(x,y);
    picture.setPixelRed(imageWidth-x, y, red);
    picture.setPixelGreen(imageWidth-x, y, green);
    picture.setPixelBlue(imageWidth-x, y, blue);

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Madgaon, Goa, India
    Rep Power


    Your code uses classes that are not a part of the JDK, s it's well nigh impossible to offer any meaningful advice.

    If you want to learn to use the relevant JDK classes, go through this tutorial:
    Trail: 2D Graphics (The Java™ Tutorials)


Similar Threads

  1. Replies: 1
    Last Post: 04-05-2011, 12:12 PM
  2. I want the output to be apper HORIZONTALLY
    By o0oNorao0o in forum New To Java
    Replies: 8
    Last Post: 01-21-2010, 12:24 PM
  3. Othello/Reversi flip checkers
    By chielt in forum Java Applets
    Replies: 10
    Last Post: 01-02-2010, 11:25 PM
  4. Random coin flip application
    By Boomer1 in forum New To Java
    Replies: 8
    Last Post: 12-18-2009, 02:57 AM
  5. How to duplicat drawOval horizontally?
    By ntagrafix in forum AWT / Swing
    Replies: 1
    Last Post: 12-03-2009, 09:37 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