Faster way to set a (PNG) bitmap color instead of pixel by pixel

前端 未结 2 1824
礼貌的吻别
礼貌的吻别 2020-12-21 22:07

I have some png files that I am applying a color to. The color changes depending on a user selection. I change the color via 3 RGB values set from another method. The png

相关标签:
2条回答
  • 2020-12-21 22:28

    Have you looked at the functions available in Bitmap? Something like extractAlpha sounds like it might be useful. You an also look at the way functions like that are implemented in Android to see how you could adapt it to your particular case, if it doesn't exactly meet your needs.

    0 讨论(0)
  • 2020-12-21 22:34

    The answer that worked for me was a write up Square did here Transparent jpegs

    They provide a faster code snippet for doing this exact thing. I tried extractAlpha and it didn't work but Square's solution did. Just modify their solution to instead modify the color bit and not the alpha bit.

    i.e.

    pixels[x] = (pixels[x] & 0xFF000000) | (color & 0x00FFFFFF);
    
    0 讨论(0)
提交回复
热议问题