You are on page 1of 2

BLACK WHITE

* HAPUS YANG TIDAK PERLU


package pkg20172205067_munirah;
import java.awt.Color;
import java.io.File;
import java.io.IOException;
import java.awt.image.BufferedImage;
import javax.imageio.ImageIO;
/**
* @author Munirah
* 20172205067
* STMIK AKBA MAKASSAR
*/
public class BlackWhite {
public static void main(String[] args) throws IOException {
// TODO code application logic here
BufferedImage img = null;
try {
File input = new File("E:\\PCD gambar\\black.png");
img = ImageIO.read(input);
}
catch (Exception e) {
System.out.println(e);
}

int width = img.getWidth();


int height = img.getHeight();
for (int y = 0;y < height; y++)
{
for (int x = 0;x < width; x++)
{
Color c = new Color(img.getRGB(x,y));
int r = c.getRed();
int g = c.getGreen();
int b = c.getBlue();
int avg = (r+g+b)/3;
System.out.print(" "+avg);
if (avg >=100) {
avg=0;
} else {
avg = 255;
}
Color avgBaru = new Color(avg, avg, avg);
img.setRGB(x,y,avgBaru.getRGB());
}
System.out.println("");
}
File Output = new File("E:\\PCD gambar\\white.png");
ImageIO.write(img, "png" , Output);
}
}

You might also like