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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。