I need to change a particular color of a PNG stored in the SDCard. I can't use tintcolor over a bitmap or over any other object because this will tint all the image not a particular pixel color.
Why do I need to do this?
I'm trying to develop an avatar application and I want to be able to change the hair of the avatar with any color I select from a palette. This Hair have two colors, one for the border and the other for the rest of the hair. I just want to change the air color and keep the border one.
This a simple case but there could be more than one color in the image.
I was looking up for a solution. This is the only thing I found (meaby there could be more but I am not lucky):
Android Bitmap: Convert transparent pixels to a color
And this is what it is exposed there:
Bitmap b = ...;
for(int x = 0; x<b.getWidth(); x++){
for(int y = 0; y<b.getHeight(); y++){
if(b.getPixel(x, y) == Color.TRANSPARENT){
b.setPixel(x, y, Color.WHITE);
}
}
}
I want to know if there is a better way to do this. Something like a:
bipmapImage.changeColor(originalColor, newColor);
I don't know if using a loop to check pixel a pixel is a good performance. Imagine a 1080 x 1080 image.
Thanks in advance.