Kann ich ein komplett weißes Bild in Java erstellen ohne ein Bild zu importieren?
Vielen Dank. Es hat funktionier.Da könnte es schon ausreichen, einfach ein BufferedImage zu erstellen.
Sollte es nicht direkt weiss sein, dann kannst Du mittels createGraphics eine Graphics Instanz erzeugen um das Bild komplett weiss zu malen.
java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
public class CreateWhiteImage {
public static void main(String[] args) {
int width = 800; // Width of the image
int height = 600; // Height of the image
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
// Set all pixels to white
int white = 0xFFFFFFFF;
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
image.setRGB(x, y, white);
}
}
// Save the image to a file
try {
File outputFile = new File("white_image.png");
ImageIO.write(image, "png", outputFile);
System.out.println("Image created successfully!");
} catch (IOException e) {
System.out.println("Error occurred while creating the image: " + e.getMessage());
}
}
}