Hey, I’m using Libgdx and I want to take a texture, replace all occurances of a color with another specified color.
This is what I have so far, I’m just not sure on changing the colors (I’m very new to Pixmaps, so I’m sure there are errors everywhere):
// e.g. replace all red pixels with green pixels: replaceColor(Assets.exampleTexture, 0xFF0000, 0x00FF00);
public Texture replaceColor(Texture texture, int c1, int c2) {
TextureData textureData = texture.getTextureData();
textureData.prepare();
Pixmap pixmap = textureData.consumePixmap();
ByteBuffer pixels = pixmap.getPixels();
while(pixels.hasRemaining()) {
if(pixels.getInt() == c1) pixels.putInt(c2);
}
pixels.rewind();
return new Texture(pixmap);
}
Thanks.