I see that your character has eyes and some kind of attribute that should be safe during color changes, so we need more control over this resource, so we will convert it to a bitmap:
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.brown_man);
Your bitmap may not change, so to change it:
Bitmap myBitmap = bitmap.copy(Bitmap.Config.RGB_565, true);
Then we have to getPixels() and re setPixels() with the given color:
int[] pixels = new int[myBitmap.getHeight() * myBitmap.getWidth()]; myBitmap.getPixels(pixels, 0, myBitmap.getWidth(), 0, 0, myBitmap.getWidth(), myBitmap.getHeight()); for (int i = 0; i < pixels.length; i++) { if (pixels[i] == color ) pixels[i] = newColor ; } myBitmap.setPixels(pixels, 0, myBitmap.getWidth(), 0, 0, myBitmap.getWidth(), myBitmap.getHeight());
So you can use this bitmap as you want.
Some things to consider:
- Your resource character must have a color of height resolution in order to simplify its definition and change.
source share