0

I am wondering what logic Android uses to calculate the final color of a view given two semi-transparent views being stacked.

What I need to do specifically is take two semi-transparent views (let's say with backgrounds #66000000 and #33000000) and figure out what the equivalent singular view COLOR would be.

I have tried ColorUtils.blendARGB but this does not give me the correct value.

HaydenKai
  • 871
  • 7
  • 31
  • Just making sure you aren't looking for this: https://stackoverflow.com/questions/8280027/what-does-porterduff-mode-mean-in-android-graphics-what-does-it-do – Morrison Chang Aug 09 '17 at 08:18
  • No, I need a mathematical calculation to figure out the resulting color – HaydenKai Aug 09 '17 at 08:24

1 Answers1

0

Ok this formula seems to work for what I needed:

C1=[R1,G1,B1] is the foreground pixel color.

C2=[R2,G2,B2] is the background pixel color.

p1 is the opacity percentage of the foreground pixel. (0.4) in my case

p2 is the opacity percentage of the background pixel. (0.2)

NewPixelColor = (p1*c1+p2*c2-p1*p2*c2)/(p1+p2-p1*p2)

NewPixelOpacity = p1+p2-p1*p2

HaydenKai
  • 871
  • 7
  • 31