In Android, how can I change a color on a bitmap to another color?

431 views Asked by At

I have a bitmap and want to be able to change all black pixels in that bitmap to blue. I know you can do this via Bitmap.setPixel but that process is extremely slow (believe me, I tried it...even doing the setPixels instead of setPixel).

Researching this is see where people recommend using PorterDuff Xor, but there isn't any posts on how this was successfully done. Lots of people asking...no one spelling out the answer.

So using, paint, bitmap, and canvas, how do you change every black pixel to all blue ones?

Thanks!

1

There are 1 answers

1
Yevgeny Simkin On BEST ANSWER

you just pull the pixels of the bitmap

myBitmap.getPixels(myPixels, 0 0, 0, 0, myBitmap.getWidth(), myBitmap.getHeight())

and loop over myPixels looking for whatever color you wish and modifying that pixel to whatever color you prefer.