** Important update, see below! **
I am creating a program that changes the pixels of a BufferedImage to a specific color when that pixel fulfills a set of conditions in Java. However, when I write the image to disk, the pixels that need to be painted are black.
First, I define the color using RGB codes:
Color purple = new Color(82, 0, 99);
int PURPLE = purple.getRGB();
Then I read the image I want to change from a file in BufferedImage called "blank":
BufferedImage blank = ImageIO.read(new File("some path"));
Now scroll through the pixels, and when the pixel at the location (x, y) matches the criteria, change its color to purple:
blank.setRGB(x, y, PURPLE);
Now write "empty" to disk.
File output = new File("some other path");
ImageIO.write(blankIn, "png", output); // try-catch blocks intentionally left out
"" , , , . , setRGB , "" . , Graphics2D setRGB, .
, :
blank.setRGB(x, y, ((82 << 16) + (0 << 8) + 99));
, , , , , , ( , , , ).
** :
blank.setRGB(x, y, Color.RED.getRGB());
, , setRGB, , . , , .