Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.*;
- import java.awt.image.*;
- import javax.swing.*;
- public class OFImage extends BufferedImage
- {
- public OFImage(BufferedImage image)
- {
- super(image.getColorModel(), image.copyData(null), image.isAlphaPremultiplied(), null);
- }
- public OFImage(int width, int height)
- {
- super(width, height, TYPE_INT_RGB);
- }
- public void setPixel(int x, int y, Color warna)
- {
- int pixel = warna.getRGB();
- setRGB(x, y, pixel);
- }
- public Color getPixel(int x, int y)
- {
- int pixel = getRGB(x, y);
- return new Color(pixel);
- }
- public void darker() {
- int height = getHeight();
- int width = getWidth();
- for (int i = 0; i < height; i++)
- {
- for (int j = 0; j < width; j++)
- {
- setPixel(j, i, getPixel(j, i).darker());
- }
- }
- }
- public void lighter()
- {
- int height = getHeight();
- int width = getWidth();
- for (int i = 0; i < height; i++)
- {
- for (int j = 0; j < width; j++)
- {
- setPixel(j, i, getPixel(j, i).brighter());
- }
- }
- }
- public void threshold()
- {
- int height = getHeight();
- int width = getWidth();
- for (int i = 0; i < height; i++)
- {
- for (int j = 0; j < width; j++)
- {
- Color pixel = getPixel(j, i);
- int brightness = (pixel.getRed() + pixel.getBlue() + pixel.getGreen()) / 3;
- if (brightness <= 85)
- {
- setPixel(j, i, Color.BLACK);
- }
- else if (brightness <= 85 * 2)
- {
- setPixel(j, i, Color.GRAY);
- }
- else
- {
- setPixel(j, i, Color.WHITE);
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement