So i have made this program and i wanted it t create a 8 by 8 sized image with only Black and White but it does only display a white color instead of randomly spread black and white. Here is my code. If someone can help that'd be great :D
package de.gamingengine.main;
import java.awt.Color;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.File;
import javax.imageio.ImageIO;
public class Main {
public static void main(String args[])throws IOException {
int width = 8;
int height = 8;
Color c = null;
BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
File f = null;
for(int y = 0; y < height; y++) {
for(int x = 0; x < width; x++) {
int blackorwhite = (int)Math.random()*10;
if(blackorwhite >= 5) {
c = Color.BLACK;
} else if(blackorwhite < 5){
c = Color.WHITE;
}
img.setRGB(x, y, c.getRGB());
}
}
try {
f = new File("C:\\Users\\Linus\\Desktop\\Out.png");
ImageIO.write(img, "png", f);
} catch (IOException e) {
System.out.println("Error: " + e);
}
}
}