Gave it a quick lookover, and have had success with the getRGB method in the Color API, although the values are a bit foreign I think I have a better understanding for how they work.
I ran into some issues with the setRGB method for image, and have developed a workaround for simple cases. I've noticed the method does not successfully convert sRGB values to those provided typically, but if that particular color is already present in the image it is successful. So a simple workaround, if you know the colors you'll be providing is to just ensure at least one pixel per region on your image contains one of the colors you need, and if necessary paint it over in the colorizing method.
Although this is fine for the project I'm attempting to include it in, especially for more complex user interfaces I had hoped colors could be chosen and set within a Java application itself, if for example the user wanted to specify which colors to use via a JColorChooser or similar.This wouldn't work with this workaround, so any ideas into how this could be achieved would be very welcome.
Before I forget, here's an SSCCE, hopefully it helps explain.
//Not a real class in my project, for demonstration's sake
public ImageColorizer(Color color) throws IOException{
BufferedImage image = ImageIO.read(new File("example.png"));
int sRGBColor = color.getRGB();
colorizeImage(image, sRGBColor);
}
protected final void colorizeImage(BufferedImage image, int color){
for(int i = 0; i < image.getWidth(); i++){
for(int j = 0; j < image.getHeight(); j++){
if(image.getRGB(i,j) != 0){ //0 represents a transparent pixel- these images are monochrome
image.setRGB(i, j, color);
}
}
}
}
This is a very simplified version of this part of the problem. Were this code to be run, with the colors method having a sRGB value not found anywhere in the image, the setRGB method in this case would either set it to one already found in the image (thus far only tested with monochrome images), or matt black. If there were some way any color could be passed to the ImageColorizer and be effective in recolorizing the image, it would achieve the goal I'm after.