Guest User

Untitled

a guest
Dec 7th, 2020
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.08 KB | None | 0 0
  1.  
  2. /**
  3.  * Write a description of class OFImage here.
  4.  *
  5.  * @author (Aristya)
  6.  * @version (7.12)
  7.  */
  8. import java.awt.*;
  9. import java.awt.image.*;
  10. import javax.swing.*;
  11.  
  12. public class OFImage extends BufferedImage
  13. {
  14.     public OFImage(BufferedImage image)
  15.     {
  16.         super(image.getColorModel(), image.copyData(null), image.isAlphaPremultiplied(), null);
  17.     }
  18.  
  19.     public OFImage(int width, int height)
  20.     {
  21.         super(width, height, TYPE_INT_RGB);
  22.     }
  23.  
  24.     public void setPixel(int x, int y, Color warna)
  25.     {
  26.         int pixel = warna.getRGB();
  27.         setRGB(x, y, pixel);
  28.     }
  29.  
  30.     public Color getPixel(int x, int y)
  31.     {
  32.         int pixel = getRGB(x, y);
  33.         return new Color(pixel);
  34.     }
  35.  
  36.     public void darker() {
  37.         int height = getHeight();
  38.         int width = getWidth();
  39.         for (int i = 0; i < height; i++)
  40.         {
  41.             for (int j = 0; j < width; j++)
  42.             {
  43.                 setPixel(j, i, getPixel(j, i).darker());
  44.             }
  45.         }
  46.     }
  47.  
  48.     public void lighter()
  49.     {
  50.         int height = getHeight();
  51.         int width = getWidth();
  52.         for (int i = 0; i < height; i++)
  53.         {
  54.             for (int j = 0; j < width; j++)
  55.             {
  56.                 setPixel(j, i, getPixel(j, i).brighter());
  57.             }
  58.         }
  59.     }
  60.  
  61.     public void threshold()
  62.     {
  63.         int height = getHeight();
  64.         int width = getWidth();
  65.         for (int i = 0; i < height; i++)
  66.         {
  67.             for (int j = 0; j < width; j++)
  68.             {
  69.                 Color pixel = getPixel(j, i);
  70.                 int brightness = (pixel.getRed() + pixel.getBlue() + pixel.getGreen()) / 3;
  71.                 if (brightness <= 85)
  72.                 {
  73.                     setPixel(j, i, Color.BLACK);
  74.                 }
  75.                 else if (brightness <= 85 * 2)
  76.                 {
  77.                     setPixel(j, i, Color.GRAY);
  78.                 }
  79.                 else
  80.                 {
  81.                     setPixel(j, i, Color.WHITE);
  82.                 }
  83.             }
  84.         }
  85.     }
  86. }
Advertisement
Add Comment
Please, Sign In to add comment