Results 1 to 2 of 2

Thread: Mirror image in Java

  1. #1
    Join Date
    Oct 2008
    Posts
    24

    Mirror image in Java

    I am here with a problem in a program having a mirror image in java, that the mirror is half of the picture!
    Code:
      public class (pixels 
      public static void main (String [] args) ( 
      Picture img = new Picture ( "E: \ \ fac \ \ ITI \ \ work 2 ITI \ \ coracao_azul.jpg"); 
      int colNum img.getWidth = (); 
      int linNum = img.getHeight (); 
      int a = colNum; 
      int b = linNum; 
     
      for (int c = 0; c <colNum c + +) ( 
      for (int l = 0; l <linNum; k + +) ( 
      Pixel thisP = img.getPixel (c, l); 
     
      img.getPixel (c-1, bl-1). setRed (img.getPixel (c, l). getRed ()); 
      img.getPixel (c-1, bl-1). setGreen (img.getPixel (c, l). getGreen ()); 
      img.getPixel (c-1, bl-1). setBlue (img.getPixel (c, l). getBlue ()); 
      ) 
      ) 
     
     
     
      img.explore (); 
      ) 
      )
    I can not figure out where the problem is. Someone let the sight it.

  2. #2
    Join Date
    May 2008
    Posts
    2,297

    Re: Mirror image in Java

    I do not understand anything about Java code that you provided (yet) but for what I read in your code, what is happening in a row of pixels is,

    1 2 3 4 5 6 7 8 9 <- top
    1 2 3 4 5 6 7 8 1
    1 2 3 4 5 6 7 2 1
    1 2 3 4 5 6 3 2 1
    1 2 3 4 5 4 3 2 1
    1 2 3 4 5 4 3 2 1
    1 2 3 4 5 4 3 2 1
    1 2 3 4 5 4 3 2 1
    1 2 3 4 5 4 3 2 1
    1 2 3 4 5 4 3 2 1 <- end
    The bold position that the final result shows, the red position where it went for the R, G and B. It takes a position (in red) and replaces another (in bold) for that. One can get confused what is bold or red, but the end result is the same.

    What I mean is that you think evil in the algorithm. You should replace the two positions and run the algorithm by half the length of the image.

    1 2 3 4 5 6 7 8 9 <- top
    9 2 3 4 5 6 7 8 1 <- exchanging the top spot with the last
    9 8 3 4 5 6 7 2 1 <- change the second position with the penultimate
    9 8 7 4 5 6 3 2 1 and so on
    9 8 7 6 5 4 3 2 1
    9 8 7 6 5 4 3 2 1 <- should stop: arrived in the middle
    You need a temporary variable that stores the value of the pixel you are going to modify, then as that has the pixel color pixel corresponding to the opposite side, and while you lack: replace the pixel on the side opposite the temporary variable that has pixel value of the original.

    I made myself clear?

Similar Threads

  1. Flip or mirror image a photo in Windows Live photo Gallery?
    By Rahul Surya in forum Windows Software
    Replies: 3
    Last Post: 04-05-2012, 04:23 PM
  2. Replies: 4
    Last Post: 27-05-2011, 10:26 AM
  3. Apple iPad 2 mirror image to computer
    By The$Tourist in forum Portable Devices
    Replies: 11
    Last Post: 29-04-2011, 12:50 PM
  4. Segment an image in java
    By Logan 2 in forum Software Development
    Replies: 7
    Last Post: 19-04-2010, 12:15 AM
  5. GUI image program java
    By Caden Fernandes in forum Software Development
    Replies: 3
    Last Post: 12-11-2009, 11:48 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,978,559.62490 seconds with 17 queries