2010-08-30 155 views
0

对于this project我使用Python的colorsys将RGB转换为HSV反之则能够操纵饱和度和亮度,但我注意到,一些颜色产生虚假的结果。十六进制RGB <-> HSV <->色彩空间转换与Python

例如,如果我采取任何基色没有任何问题:

但是,如果我选择了一个随机的RGB颜色,并将其转换为HSV,我有时也得到虚假的结果。

有时这些假结果发生在我增加或减少颜色的亮度或饱和度时。

在这个例子中明度10%,20%和饱和度为100%是假的:

我不太清楚为什么会发生,也不应该怎么解决这个问题..

+0

你能发布你的代码吗? – 2010-08-30 03:25:09

+0

您的图像链接被损坏:( – Tony 2013-12-18 14:58:26

回答

2

问题是在你的代码DEC2HEX:

def dec2hex(d): 
    """return a two character hexadecimal string representation of integer d""" 
    r = "%X" % d 
    return r if len(r) > 1 else r+r 

当你的值小于16,你复制它获得的价值,换句话说,1乘以7.你想要这个:

def dec2hex(d): 
    """return a two character hexadecimal string representation of integer d""" 
    return "%02X" % d 
+0

非常感谢:) – 2010-08-30 03:51:48

相关问题