Go Down

Topic: [Solved] How to calculate a color based on 2 other colors (Read 528 times)previous topic - next topic

guix

Dec 05, 2012, 02:43 amLast Edit: Dec 05, 2012, 03:19 am by guix Reason: 1
Hello all, not sure if it's the right place to post this but anyway

I would like to know how to calculate a color that my display should show when combining the background and foreground colors..

Not sure how to describe, but say I have an foreground RGB value that is white, and a background RGB value that is black. I would like to add some transparency to the foreground color, so it should display a grey on the black background.

How to do this (for any foreground/background combination) ? There must be some algorithms but I don't find, or don't know what to search for.

An example, in Paint.NET I make a red background, and then I place a yellow pixel with an alpha value of 200. Then use the color picker tool to retrieve the color of the pixel I've just placed:
Code: [Select]
`           R    G    B      ARed:     255,   0,   0    255Yellow:  220, 216,   0    200Result:  227, 169,   0    255`

I can't find the calculation required to obtain this RGB result.

Thanks for any help

Edit: I've found the answer!..

R = 227 = ( (200/255) * 220 ) + ( (1 - (200/255)) * 255 )
G = 169 = ( (200/255) * 216 ) + ( (1 - (200/255)) * 0 )
B = 0 = ( (200/255) * 0 ) + ( (1 - (200/255)) * 0 ) ...

Go Up