“Python/docs/3.9/library/colorsys”的版本间差异
来自菜鸟教程
Python/docs/3.9/library/colorsys
(autoload) |
小 (Page commit) |
||
第1行: | 第1行: | ||
+ | {{DISPLAYTITLE:colorsys — 颜色系统之间的转换 — Python 文档}} | ||
<div id="module-colorsys" class="section"> | <div id="module-colorsys" class="section"> | ||
<span id="colorsys-conversions-between-color-systems"></span> | <span id="colorsys-conversions-between-color-systems"></span> | ||
− | = | + | = colorsys — 颜色系统之间的转换 = |
− | ''' | + | '''源代码:''' [[#id1|<span id="id2" class="problematic">:source:`Lib/colorsys.py`</span>]] |
− | + | ||
− | + | ----- | |
− | + | ||
− | + | [[#module-colorsys|colorsys]] 模块定义了在计算机显示器中使用的 RGB(红绿蓝)颜色空间和其他三个坐标系中表示的颜色之间颜色值的双向转换:YIQ、HLS(色相亮度饱和度)和 HSV(色相饱和度)饱和值)。 所有这些颜色空间中的坐标都是浮点值。 在 YIQ 空间中,Y 坐标在 0 和 1 之间,但 I 和 Q 坐标可以为正也可以为负。 在所有其他空间中,坐标都在 0 和 1 之间。 | |
− | |||
− | 0 | ||
− | |||
<div class="admonition seealso"> | <div class="admonition seealso"> | ||
− | + | 也可以看看 | |
− | + | 有关色彩空间的更多信息,请访问 https://poynton.ca/ColorFAQ.html 和 https://www.cambridgeincolour.com/tutorials/color-spaces.htm . | |
− | https://poynton.ca/ColorFAQ.html | ||
− | https://www.cambridgeincolour.com/tutorials/color-spaces.htm. | ||
</div> | </div> | ||
− | + | [[#module-colorsys|colorsys]] 模块定义了以下函数: | |
− | ; < | + | ; <span class="sig-prename descclassname"><span class="pre">colorsys.</span></span><span class="sig-name descname"><span class="pre">rgb_to_yiq</span></span><span class="sig-paren">(</span>''<span class="n"><span class="pre">r</span></span>'', ''<span class="n"><span class="pre">g</span></span>'', ''<span class="n"><span class="pre">b</span></span>''<span class="sig-paren">)</span> |
− | : | + | : 将颜色从 RGB 坐标转换为 YIQ 坐标。 |
− | ; < | + | ; <span class="sig-prename descclassname"><span class="pre">colorsys.</span></span><span class="sig-name descname"><span class="pre">yiq_to_rgb</span></span><span class="sig-paren">(</span>''<span class="n"><span class="pre">y</span></span>'', ''<span class="n"><span class="pre">i</span></span>'', ''<span class="n"><span class="pre">q</span></span>''<span class="sig-paren">)</span> |
− | : | + | : 将颜色从 YIQ 坐标转换为 RGB 坐标。 |
− | ; < | + | ; <span class="sig-prename descclassname"><span class="pre">colorsys.</span></span><span class="sig-name descname"><span class="pre">rgb_to_hls</span></span><span class="sig-paren">(</span>''<span class="n"><span class="pre">r</span></span>'', ''<span class="n"><span class="pre">g</span></span>'', ''<span class="n"><span class="pre">b</span></span>''<span class="sig-paren">)</span> |
− | : | + | : 将颜色从 RGB 坐标转换为 HLS 坐标。 |
− | ; < | + | ; <span class="sig-prename descclassname"><span class="pre">colorsys.</span></span><span class="sig-name descname"><span class="pre">hls_to_rgb</span></span><span class="sig-paren">(</span>''<span class="n"><span class="pre">h</span></span>'', ''<span class="n"><span class="pre">l</span></span>'', ''<span class="n"><span class="pre">s</span></span>''<span class="sig-paren">)</span> |
− | : | + | : 将颜色从 HLS 坐标转换为 RGB 坐标。 |
− | ; < | + | ; <span class="sig-prename descclassname"><span class="pre">colorsys.</span></span><span class="sig-name descname"><span class="pre">rgb_to_hsv</span></span><span class="sig-paren">(</span>''<span class="n"><span class="pre">r</span></span>'', ''<span class="n"><span class="pre">g</span></span>'', ''<span class="n"><span class="pre">b</span></span>''<span class="sig-paren">)</span> |
− | : | + | : 将颜色从 RGB 坐标转换为 HSV 坐标。 |
− | ; < | + | ; <span class="sig-prename descclassname"><span class="pre">colorsys.</span></span><span class="sig-name descname"><span class="pre">hsv_to_rgb</span></span><span class="sig-paren">(</span>''<span class="n"><span class="pre">h</span></span>'', ''<span class="n"><span class="pre">s</span></span>'', ''<span class="n"><span class="pre">v</span></span>''<span class="sig-paren">)</span> |
− | : | + | : 将颜色从 HSV 坐标转换为 RGB 坐标。 |
− | + | 例子: | |
<div class="highlight-python3 notranslate"> | <div class="highlight-python3 notranslate"> | ||
第50行: | 第46行: | ||
<div class="highlight"> | <div class="highlight"> | ||
− | < | + | <syntaxhighlight lang="python3">>>> import colorsys |
− | + | >>> colorsys.rgb_to_hsv(0.2, 0.4, 0.4) | |
(0.5, 0.5, 0.4) | (0.5, 0.5, 0.4) | ||
− | + | >>> colorsys.hsv_to_rgb(0.5, 0.5, 0.4) | |
− | (0.2, 0.4, 0.4)</ | + | (0.2, 0.4, 0.4)</syntaxhighlight> |
+ | |||
+ | </div> | ||
</div> | </div> | ||
</div> | </div> | ||
+ | <div class="clearer"> | ||
+ | |||
+ | |||
</div> | </div> | ||
− | [[Category:Python 3.9 | + | [[Category:Python 3.9 文档]] |
2021年10月31日 (日) 04:51的最新版本
colorsys — 颜色系统之间的转换
源代码: :source:`Lib/colorsys.py`
colorsys 模块定义了在计算机显示器中使用的 RGB(红绿蓝)颜色空间和其他三个坐标系中表示的颜色之间颜色值的双向转换:YIQ、HLS(色相亮度饱和度)和 HSV(色相饱和度)饱和值)。 所有这些颜色空间中的坐标都是浮点值。 在 YIQ 空间中,Y 坐标在 0 和 1 之间,但 I 和 Q 坐标可以为正也可以为负。 在所有其他空间中,坐标都在 0 和 1 之间。
也可以看看
有关色彩空间的更多信息,请访问 https://poynton.ca/ColorFAQ.html 和 https://www.cambridgeincolour.com/tutorials/color-spaces.htm .
colorsys 模块定义了以下函数:
- colorsys.rgb_to_yiq(r, g, b)
- 将颜色从 RGB 坐标转换为 YIQ 坐标。
- colorsys.yiq_to_rgb(y, i, q)
- 将颜色从 YIQ 坐标转换为 RGB 坐标。
- colorsys.rgb_to_hls(r, g, b)
- 将颜色从 RGB 坐标转换为 HLS 坐标。
- colorsys.hls_to_rgb(h, l, s)
- 将颜色从 HLS 坐标转换为 RGB 坐标。
- colorsys.rgb_to_hsv(r, g, b)
- 将颜色从 RGB 坐标转换为 HSV 坐标。
- colorsys.hsv_to_rgb(h, s, v)
- 将颜色从 HSV 坐标转换为 RGB 坐标。
例子:
>>> import colorsys
>>> colorsys.rgb_to_hsv(0.2, 0.4, 0.4)
(0.5, 0.5, 0.4)
>>> colorsys.hsv_to_rgb(0.5, 0.5, 0.4)
(0.2, 0.4, 0.4)