Advertisement
VinaDR

Untitled

Dec 12th, 2019
290
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.78 KB | None | 0 0
  1. /**
  2.  *
  3.  * @author RyanR
  4.  */
  5. import java.awt.*;
  6. import java.awt.image.*;
  7. import javax.swing.*;
  8.  
  9. public class JImg extends BufferedImage {
  10.    public JImg(BufferedImage img) {
  11.         super(img.getColorModel(), img.copyData(null),
  12.         img.isAlphaPremultiplied(), null);
  13.     }
  14.    public JImg(int width, int height) {
  15.         super(width, height, TYPE_INT_RGB);
  16.     }
  17.    public void setPixel(int x, int y, Color c) {
  18.         int pixel = c.getRGB();
  19.         setRGB(x,y,pixel);
  20.     }
  21.    public Color getPixel(int x,int y) {
  22.         int pixel = getRGB(x,y);
  23.         return new Color(pixel);
  24.     }
  25.     public void dark() {
  26.         int height = getHeight();
  27.         int width = getWidth();
  28.         for (int y=0; y<height; y++) {
  29.             for(int x=0; x<width; x++) {
  30.                 setPixel(x,y,getPixel(x,y).darker());
  31.             }
  32.         }
  33.     }
  34.     public void bright() {
  35.         int height = getHeight();
  36.         int width = getWidth();
  37.         for (int y=0; y<height; y++) {
  38.             for(int x=0; x<width; x++) {
  39.                 setPixel(x,y,getPixel(x,y).brighter());
  40.             }
  41.         }
  42.     }
  43.     public void monokrom() {
  44.         int height = getHeight();
  45.         int width = getWidth();
  46.         for (int y=0; y<height; y++) {
  47.             for(int x=0; x<width; x++) {
  48.                 Color pixel = getPixel(x,y);
  49.                 int brightness = (pixel.getRed() + pixel.getBlue() +
  50.                 pixel.getGreen());
  51.                 if(brightness <= 85) {
  52.                     setPixel(x,y,Color.BLACK);
  53.                 }
  54.                 else if(brightness <= 170) {
  55.                     setPixel(x,y,Color.GRAY);
  56.                 }
  57.                 else {
  58.                     setPixel(x,y,Color.WHITE);
  59.                 }
  60.             }
  61.         }
  62.     }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement