Results 1 to 3 of 3
  1. #1
    Cinnic is offline Member
    Join Date
    Jun 2013
    Posts
    12
    Rep Power
    0

    Default rearranging a 2d picture array (flipRightHalfHorizontal)

    I want to read the array of pixels. Then I want to take the last column array and switch it with the middle column array, continuing. This is my attempt of a horizontal flip on the right half of the picture but I haven't quite got it figured out. Some direction would be welcomed. Thanks
    Java Code:
    //*********************************************FLIP RIGHT HALF HORIZONTAL*************************************
    public static void flipRightHalfHorizontal ()
         {
          Image img = ImageViewer.getImage();
          
          //get a two dimensional array of colors representing the color for each pixel in the image
          Color [][] c = img.getPixelColors();
          
          int maxRows = c.length;
          int maxCols = c[0].length;
          int rotate = maxCols-1;
          
          Color [][] newC =new Color[maxRows][maxCols];
          
          //copy last column of old array into middle column of new array
          for (int rowNumber = 0; rowNumber < maxRows; rowNumber++)
              {
               for (int colNumber=0; colNumber < maxCols; colNumber++)
                   {
                    if (colNumber > (maxCols/2))
                       {
                        newC [rowNumber][rotate] = c[rowNumber][colNumber];
                       }                   
                    else
                       {
                        newC [rowNumber][colNumber] = c[rowNumber][colNumber];
                       }
                   }
                rotate--;
              }
          ImageViewer.createImage(newC);
         }

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,601
    Rep Power
    5

    Default Re: rearranging a 2d picture array (flipRightHalfHorizontal)

    Are you required to do it this way? Why not just use subImages of a BufferedImage in combination with AffinetTransforms?

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  3. #3
    Cinnic is offline Member
    Join Date
    Jun 2013
    Posts
    12
    Rep Power
    0

    Default Re: rearranging a 2d picture array (flipRightHalfHorizontal)

    Yes. Unfortunately, it has to be done like this.

Similar Threads

  1. Replies: 1
    Last Post: 05-24-2012, 04:44 PM
  2. Getting a picture out of a jar?
    By Zman3359 in forum New To Java
    Replies: 4
    Last Post: 02-02-2011, 11:55 PM
  3. Get screenshot(picture) of own pc
    By shekhar2010 in forum New To Java
    Replies: 5
    Last Post: 01-24-2010, 03:48 AM
  4. Picture help
    By deathnote11 in forum AWT / Swing
    Replies: 13
    Last Post: 06-03-2008, 05:46 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
  •