daily pastebin goal
23%
SHARE
TWEET

Untitled

a guest Dec 10th, 2018 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.awt.Color;
  2.  
  3. /**
  4.  * Ujian Akhir Semester
  5.  * Kelas PBO B
  6.  * @author Hendra Ramadani (05111740000055)
  7.  * 10 December 2018
  8.  */
  9. public class PixelizeFilter extends Filter
  10. {
  11.     /**
  12.      * Constructor for objects of class PixelizeFilter.
  13.      * @param name The name of the filter.
  14.      */
  15.     public PixelizeFilter(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.         final int PIXEL_SIZE = 5;
  28.         int width = image.getWidth();
  29.         int height = image.getHeight();
  30.        
  31.         for(int y = 0; y < height; y += PIXEL_SIZE) {
  32.             for(int x = 0; x < width; x += PIXEL_SIZE) {
  33.                 Color pix = image.getPixel(x, y);
  34.                 for(int dy = y; dy < y + PIXEL_SIZE; dy++) {
  35.                     for(int dx = x; dx < x + PIXEL_SIZE; dx++) {
  36.                         if( dx < width && dy < height )
  37.                             image.setPixel(dx, dy, pix);
  38.                     }
  39.                 }
  40.             }
  41.         }
  42.     }
  43. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top