Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.*;
- import java.awt.image.BufferedImage;
- /**
- * OFImage ialah Class yang mendefinisikan image dalam format Object First
- */
- public class OFImage extends BufferedImage {
- /**
- * membuat Copy-an OFimage dari BufferedImage
- * @param image image yang mau di-copy
- */
- public OFImage(BufferedImage image){
- super(image.getColorModel(), image.copyData(null),
- image.isAlphaPremultiplied(), null);
- }
- /**
- * memmbuat OFImage dengan ukuran yang spesifik dan
- * konten yang tak spesifik
- * @param width lebar gambar
- * @param height tinggi gambar
- */
- public OFImage( int width, int height){
- super(width,height,TYPE_INT_RGB);
- }
- /**
- * mengatur pixel yang diberikan dari image ke warna yang spesifik
- * color merepresentasikan nilai RGB
- * @param x posisi-x dari pixel
- * @param y posisi-y dari pixel
- * @param col warna dari pixel
- */
- public void setPixel(int x, int y, Color col){
- int pixel =col.getRGB();
- setRGB(x, y, pixel);
- }
- /**
- * mendapatkan nilai warna pada posisi spesifik pada pixel
- * @param x posisi-x dari pixel
- * @param y posisi-y dari pixel
- * @return warna dari posisi [ixel yang diberikan
- */
- public Color getPixel(int x, int y){
- int pixel = getRGB(x, y);
- return new Color(pixel);
- }
- /**
- * membuat gambar jadi sedikit lebih gelap
- */
- public void darker()
- {
- int height = getHeight();
- int width = getWidth();
- for(int y=0; y < height; y++){
- for (int x=0; x < width; x++){
- setPixel(x,y, getPixel(x,y).darker());
- }
- }
- }
- /**
- * membuat gambar jadi sedikit lebih terang
- */
- public void lighter(){
- int height = getHeight();
- int width = getWidth();
- for(int y=0; y < height; y++){
- for (int x=0; x < width; x++){
- setPixel(x,y, getPixel(x,y).brighter());
- }
- }
- }
- /**
- * melakukan tiga level opereasi thershold
- */
- public void threshold() {
- int height = getHeight();
- int width = getWidth();
- for (int y = 0; y < height; y++) {
- for (int x = 0; x < width; x++) {
- Color pixel = getPixel(x, y);
- int brightness = (pixel.getRed() + pixel.getBlue() + pixel.getGreen())/3;
- if (brightness <=85){
- setPixel(x,y, Color.BLACK);
- } else if(brightness<=170){
- setPixel(x,y, Color.GRAY);
- } else {
- setPixel(x,y, Color.WHITE);
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement