1

I have a colour value of rgb(92, 174, 224) and would like to find the rgba equivalent when the opacity is 0.5 (or any value I choose, it could be 0.4) and the background is white rgb(255, 255, 255).

I would like the answer to be in the form of an equation such as:

div (d) = rgb(92, 174, 224) ---- (The colour to match)

background (b) = rgb(255, 255, 255) ---- (The colour behind the transparent colour)

x = (d - (b*0.5)) / 0.5
r = (d - (b*0.5)) / 0.5
g = (d - (b*0.5)) / 0.5
b = (d - (b*0.5)) / 0.5
Funtastic
  • 21
  • 1
  • 4
  • What programming language are you using? – Scott Solmer Mar 04 '15 at 13:03
  • c# and asp.net, but the style is within css. I'm not looking for a method to do this. Just a formula / equation. – Funtastic Mar 04 '15 at 15:12
  • In other words I want to convert rgb to rgba where the alpha/opacity is 0.5. I want an equation so I can change the values of the target colour and the opacity, and maybe the bg colour should I want to. – Funtastic Mar 04 '15 at 15:17
  • I found this solution on webmasterworld.com: body - rgb(153,204,255) container - rgb(255,255,255) opacity:0.4 r value=(r*0.4)+(255*0.6)=153, which gives r=0 g value=(g*0.4)+(255*0.6)=204, which gives g=127 b value=(b*0.4)+(255*0.6)=255, which gives b=255 opacity div - rgb(0,127,255) or #007fff But the equation doesn't describe how to find 'r'. So the example equations I posted are how to find 'r'. But these equations didn't work with my values because they gave negative values and values above 255. – Funtastic Mar 04 '15 at 15:22
  • Have you checked the wikipedia article on [Alpha compositing](http://en.wikipedia.org/wiki/Alpha_compositing)? It's a little dense but contains some useful information. – 1000000000 Mar 04 '15 at 15:25
  • I will see if I can understand any of that. This site does rgba to rgb. http://yolijn.com/convert-rgba-to-rgb I'm not sure if their source formula can be reversed to find rgba from rgb. – Funtastic Mar 04 '15 at 15:38
  • possible duplicate of [Convert RGB to RGBA over white](http://stackoverflow.com/questions/6672374/convert-rgb-to-rgba-over-white) – BoltClock Mar 05 '15 at 04:44

1 Answers1

0

If I have catch your problem correctly, then here is something for you.

color = rgb(92, 174, 224);
// we will use color[0] to access first value

bg = rbg(255,255,255);
// we will use bg[0] to access first value

alpha = 0.6;

base = alpha/10;

Now the calculation will like follow.

ResultColor[0] = round( bg[0] - ( (bg[0] - color[0])/alpha ) - 1 )
ResultColor[1] = round( bg[1] - ( (bg[1] - color[1])/alpha ) - 1 )
ResultColor[2] = round( bg[2] - ( (bg[2] - color[2])/alpha ) - 1 )

So the resulting color will be

ResultColor = rgb(173,214,239)
Saurin Dashadia
  • 1,140
  • 11
  • 25
  • That is an interesting formula, however it's not quite what I was looking for. I want the div to have an opacity of 0.5 or maybe 0.6. While appearing the same colour as rgb(92, 174, 224). So I will find the rgba value (x, x, x, 0.5) or (x, x, x, 0.6) – Funtastic Mar 04 '15 at 16:00
  • @Funtastic if you are using rgb() color method then you can not achieve div transparency. For that you have to use rgba() instead. But here my above formula is to get rgb value equivalent to rgba color where base color is white of might be anything. so if you asign a div red color with 0.5 or 0.6 alpha in wonder what is rgb equivalent then above is the formula – Saurin Dashadia Mar 05 '15 at 04:46
  • Thanks for your help. But my question was for a rgba() equivalent. – Funtastic Mar 05 '15 at 09:31
  • Yes it is, this will give you rgba equivallent value of rgb. It is clearly stated in example. – Saurin Dashadia Mar 05 '15 at 12:45
  • Maybe there is some confusion with my use of the word 'equivalent'. What I meant to ask for was an rgba value that matches the colour of the given rgb value, with an opacity/alpha of 0.5 or 0.6. Because I need a transparent div that appears the same colour as the rgb colour, and the formula to find that value. – Funtastic Mar 06 '15 at 11:06
  • You can do it by easy equation transformation. x = y + z then z = x - y. :) Hope you got my point. – Saurin Dashadia Mar 10 '15 at 04:50