Original Post
Hey everyone. I'm working on a game that allows the player to customize some of the colors on their sprite. Right now I have a default sprite and change the color of all white pixels in-game to match what the player wants. Unfortunately, the process is unusually long, so I suspect something is wrong with the code. Here's the method:
/**
* Returns an image with the correct color changes
*/
static BufferedImage getRecoloredImage(BufferedImage source, Color replaced, Color changeTo) {
int replacedRGB = replaced.getRGB();
int changeToRGB = changeTo.getRGB();
for (int b = 0, width = source.getWidth(); b < width; b++) {
for (int c = 0, height = source.getHeight(); c < height; c++) {
if (source.getRGB(b, c) == replacedRGB) {
source.setRGB(b, c, changeToRGB);
}
}
}
return source;
}
Thanks for any help anyone can provide.