4

For a given hex color code, how can I convert it to an rbga color code where a=0.97 and the rendered color is the same as the initial hex color?

In other words, if I have #ccc, I need an rgba equivalent which stills renders the same color as #ccc but has transparency.

Josh Crozier
  • 233,099
  • 56
  • 391
  • 304
Nathan
  • 949
  • 1
  • 20
  • 35
  • 1
    The perceived color of a translucent element will depend on what it is atop: a color, multiple colors, an image, etc. If the background color of the element beneath it is constant, [see here](http://stackoverflow.com/questions/6672374/convert-rgb-rgba?rq=1) – Tim M. Sep 26 '13 at 03:22

1 Answers1

0

To convert to rgba, you have to do this:

1- Divide your hex color code to 3 parts

cccccc => cc(r)|cc(g)|cc(b)

2- For each part, convert it to int by using parseInt

r = parseInt("cc", 16)
g = parseInt("cc", 16)
b = parseInt("cc", 16)

3- Add desired alpha value to your final rgba code

Josh Crozier
  • 233,099
  • 56
  • 391
  • 304
RyanB
  • 1,287
  • 1
  • 9
  • 28