igede

Untitled

Dec 10th, 2018
260
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.94 KB | None | 0 0
  1. import java.awt.Color;
  2.  
  3. /**
  4.  * An image filter to mirror (flip) the image horizontally.
  5.  *
  6.  * @author Gede
  7.  * @version (10/12/2018)
  8.  */
  9. public class FlipVerticalFilter extends Filter
  10. {
  11.     /**
  12.      * Constructor for objects of class FlipVerticalFilter.
  13.      * @param name The name of the filter.
  14.      */
  15.     public FlipVerticalFilter(String name)
  16.     {
  17.         super(name);
  18.     }
  19.  
  20.     /**
  21.      * Apply this filter to an image.
  22.      *
  23.      * @param  image  The image to be changed by this filter.
  24.      */
  25.     public void apply(OFImage image)
  26.     {
  27.         int height = image.getHeight();
  28.         int width = image.getWidth();
  29.         for(int y = 0; y < height; y++) {
  30.             for(int x = 0; x < width / 2; x++) {
  31.                 Color left = image.getPixel(x, y);
  32.                 image.setPixel(x, y, image.getPixel(width - 1 - x, y));
  33.                 image.setPixel(width - 1 - x, y, left);
  34.             }
  35.         }
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment