Formula to determine brightness of RGB color

前端 未结 20 3134
猫巷女王i
猫巷女王i 2020-11-21 23:16

I\'m looking for some kind of formula or algorithm to determine the brightness of a color given the RGB values. I know it can\'t be as simple as adding the RGB values toget

20条回答
  •  后悔当初
    2020-11-21 23:57

    The method could vary depending on your needs. Here are 3 ways to calculate Luminance:

    • Luminance (standard for certain colour spaces): (0.2126*R + 0.7152*G + 0.0722*B) source img

    • Luminance (perceived option 1): (0.299*R + 0.587*G + 0.114*B) source img

    • Luminance (perceived option 2, slower to calculate): sqrt( 0.241*R^2 + 0.691*G^2 + 0.068*B^2 )sqrt( 0.299*R^2 + 0.587*G^2 + 0.114*B^2 ) (thanks to @MatthewHerbst) source img

    [Edit: added examples using named css colors sorted with each method.]

提交回复
热议问题