gpt4 book ai didi

python - HSL python 语法 (PIL)

转载 作者:太空宇宙 更新时间:2023-11-03 13:47:17 25 4
gpt4 key购买 nike

我在这里的代码中使用 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 的网站上,我假设亮度和饱和度都必须是百分比。 row[1] 的最大值可能是 999,因此不透明度永远不会 >1。预先感谢您的帮助!

最佳答案

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

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

http://effbot.org/imagingbook/imagedraw.htm

关于python - HSL python 语法 (PIL),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17049777/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com