GrowlingBadger
GrowlingBadger

Reputation: 178

CGColor - Determining the blended color from two UIViews that are on top of each other

I am trying to obtain the resultant CGColor (or UIColor) that would be displayed as a result of two (or perhaps more) views that are sat on top of each other each with differing colours. Obviously the view(s) nearer the foreground have an alpha value of less than 1, allowing the colour of views behind to bleed through.

Essentially, I guess I'm trying to mimic exactly what the UIView compositing process does exactly when it prepares for the painting of a scene.

NB. I'd like to steer away from a manual programmatic blend algorithm as will likely not be the same as the Cocoa blend mechanism.

I have just found this... Can I mix two UIColor together? but thought there must be an iOS/Cocoa equivalent

Upvotes: 1

Views: 869

Answers (1)

clearlight
clearlight

Reputation: 12615

Heres a tutorial-ish thing:

Blending Modes in iOS

And here is the Apple Documentation that covers blend modes. Should get you on the right track. The exact formulas are shown for each blend mode option.

Finally, see this answer:

How to get the color of a displayed pixel

Upvotes: 1

Related Questions