PIL是Python Imaging Library,它为python解释器提供了图像编辑函数。的ImageColor
模块包含颜色表和从CSS3样式颜色说明符到RGB元组的转换器。该模块由PIL.Image.Image.new()
和ImageDraw
模块等。
ImageColor.getrgb()
将颜色字符串转换为RGB元组。如果无法解析字符串,则此函数将引发一个ValueError
例外。
用法: PIL.ImageColor.getrgb(color)
参数:
color-颜色字符串
返回:(红色,绿色,蓝色[,alpha])
# importing Image module from PIL package
from PIL import Image, ImageColor
# using getrgb
im = ImageColor.getrgb("orange")
print(im)
im1 = ImageColor.getrgb("red")
print(im1)
输出:
(255, 165, 0) (255, 0, 0)
另一个示例:-这里使用了不同的颜色。
# importing Image module from PIL package
from PIL import Image, ImageColor
# using getrgb
im = ImageColor.getrgb("blue")
print(im)
im1 = ImageColor.getrgb("yellow")
print(im1)
输出:
(0, 0, 255) (255, 255, 0)
相关用法
- Python next()用法及代码示例
- Python os.dup()用法及代码示例
- Python set()用法及代码示例
- Python Decimal max()用法及代码示例
- Python PIL ImageOps.fit()用法及代码示例
- Python os.rmdir()用法及代码示例
- Python sympy.det()用法及代码示例
- Python Decimal min()用法及代码示例
- Python os.readlink()用法及代码示例
- Python os.writev()用法及代码示例
- Python os.readv()用法及代码示例
- Python PIL RankFilter()用法及代码示例
- Python os.rename()用法及代码示例
- Python os.sendfile()用法及代码示例
注:本文由纯净天空筛选整理自Sunitamamgai大神的英文原创作品 Python PIL | ImageColor.getrgb() Method。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。