Android 颜色透明度换算

简介

颜色

Android中的颜色值一般遵循RGB/ARGB标准,使用时一般以“#”字符开头,以16进制表示。 经常使用的颜色值格式为:git

#RGB
#ARGB
#RRGGBB
#AARRGGBB

其中,ARGB 依次表明透明度(alpha)、红色(red)、绿色(green)、蓝色(blue)。 以颜色值 #FF99CC00 为例,其中,FF 是透明度,99 是红色值, CC 是绿色值, 00 是蓝色值。spa

透明度

  1. 透明度分为256阶(0-255),计算机上用16进制表示为(00-ff)。透明就是0阶,不透明就是255阶,若是50%透明就是127阶(256的一半固然是128,但由于是从0开始,因此其实是127)。code

  2. 透明度 和 不透明度 是两个概念, 它们加起来是1,或者100%.orm

  3. ARGB 中的透明度alpha,表示的是不透明度。依据来自维基百科中的定义。ci

    The alpha channel is normally used as an opacity channel. If a pixel has a value of 0% in its alpha channel, it is fully transparent (and, thus, invisible), whereas a value of 100% in the alpha channel gives a fully opaque pixel (traditional digital images). Values between 0% and 100% make it possible for pixels to show through a background like a glass, an effect not possible with simple binary (transparent or opaque) transparency. It allows easy image compositing.开发

换算

在开发过程当中,UI/UE给的标注图上,全部颜色值是RGB,可是透明度常常都是百分比,例如:颜色值:#FFFFFF,透明度40%。 使用过程当中咱们须要进行换算。以以前的值为例,换算过程以下:it

  1. 将透明度转换成不透明度(转换方式参考“透明度”,第2条) 。 不透明度为60%
  2. 不透明度乘以255。 咱们获得结果:153
  3. 将计算结果转换成16进制。获得最终的不透明度:99
  4. 将不透明度和颜色值拼接成ARGB格式。获得最终的颜色值: #99FFFFFF

简单的换算,能够先将透明度,转换成不透明度,再根据下面的表格进行对应。io

100% — FF
95% — F2
90% — E6
85% — D9
80% — CC
75% — BF
70% — B3
65% — A6
60% — 99
55% — 8C
50% — 80
45% — 73
40% — 66
35% — 59
30% — 4D
25% — 40
20% — 33
15% — 26
10% — 1A
5% — 0D
0% — 00
相关文章
相关标签/搜索