Pages: [1]   Go Down
Author Topic: [Solved] How to calculate a color based on 2 other colors  (Read 237 times)
0 Members and 1 Guest are viewing this topic.
France
Offline Offline
Edison Member
*
Karma: 38
Posts: 1012
Scientia potentia est.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello all, not sure if it's the right place to post this but anyway smiley

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:
          R    G    B      A
Red:     255,   0,   0    255
Yellow:  220, 216,   0    200

Result:  227, 169,   0    255

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

Thanks for any help smiley

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 ) ... smiley
« Last Edit: December 04, 2012, 09:19:18 pm by guix » Logged

Pages: [1]   Go Up
Jump to: