RGB色彩模式是工业界的一种颜色标准,是通过对红(R)、绿(G)、蓝(B)三个颜色通道的变化以及它们相互之间的叠加来得到各式各样的颜色的,RGB即是代表红、绿、蓝三个通道的颜色。在计算机的中是怎么表达的呢?
它是由24位组成,顺序如上图所示。因此它可以用一个整型来表示。
我们用python代码实现一下,其他语言也是找个道理
#coding:utf-8
def hex2rgb(hexcolor):
rgb = [(hexcolor >> 16) & 0xff, (hexcolor >> 8) & 0xff, hexcolor & 0xff ]
return rgb
def rgb2hex(rgbcolor):
r, g, b = rgbcolor
return (r << 16) + (g << 8) + b
rgb = rgb2hex((128,128,18))
print( '整形数:' + str(rgb) )
print( 'RGB:' + str(hex2rgb( rgb )) )print( '十六进制:' + hex(rgb ))
输出结果为:
验证一下 通过搜索,我找到一个在线转换RGB值的网页
本文暂时没有评论,来添加一个吧(●'◡'●)