
18-12-2008
|
 | Member | | Join Date: May 2008
Posts: 2,278
| |
| 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, Quote:
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. Quote:
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? |