Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/299.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
HSL python语法(PIL)_Python_Python Imaging Library_Hsl - Fatal编程技术网

HSL python语法(PIL)

HSL python语法(PIL),python,python-imaging-library,hsl,Python,Python Imaging Library,Hsl,我很难在我的代码中使用hsl颜色值。。。我的目标是根据坐标索引在数据集中出现的频率更改图像中像素的不透明度。 我从csv文件中提取数据,唯一的错误是使用了无效的hsl语法。以下是我代码的一部分: for row in reader: port = int(row[0]) opacity = int(row[1])/1000 x = port % 255 y = int(port/257) color = hs

我很难在我的代码中使用hsl颜色值。。。我的目标是根据坐标索引在数据集中出现的频率更改图像中像素的不透明度。 我从csv文件中提取数据,唯一的错误是使用了无效的hsl语法。以下是我代码的一部分:

    for row in reader:
        port = int(row[0])
        opacity = int(row[1])/1000
        x = port % 255
        y = int(port/257)
        color = hsl(0, 0%, opacity)
        draw.point([(x,y)], fill=color)
        del draw  

从PIL的网站上,我假设亮度和饱和度都必须是百分比。行[1]的最大值可能是999,因此不透明度永远不会大于1。提前感谢您的帮助

PIL颜色定义为字符串,而不是实际的Python函数

color = 'hsl(%d, %d%%, %d%%)' % (hue, saturation, luminance)
draw.point((x, y), fill=color)

您是否尝试过删除百分号,所以它是这样的:
color=hsl(0,0,不透明度)
?是的,但是我得到了错误“名称“hsl”未定义”。Hrm。或者,您是否尝试过
color=hsl(0,0%,不透明度%)
?抱歉——我从未使用过PIL,只是想给你一些想法。是的,我尝试过将不透明性转换为字符串(python是否将百分比视为字符串?),并在末尾添加一个%。但是错误在0%上,这就是为什么我如此困惑的原因。根据Thomas Darr的回答,我认为您需要将
color
设置为字符串,如so
color='hsl(0,0%,%d%%)'%(不透明度)