user443654
user443654

Reputation: 929

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

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!

Upvotes: 1

Views: 430

Answers (1)

Yevgeny Simkin
Yevgeny Simkin

Reputation: 28349

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.

Upvotes: 1

Related Questions