作用:
ImageDraw.Draw.polygon() 绘制多边形。
多边形轮廓由给定坐标之间的直线以及最后一个坐标与第一个坐标之间的直线组成。
用法:
PIL.ImageDraw.Draw.polygon(xy, fill=None, outline=None)
参数:
——xy – 由 [(x1, y1), (x2, y2),…] 等2元组或 [x1,y1,x1,y1,…] 等数值组成的序列
——fill –用于填充的颜色
——outline –轮廓使用的颜色
注
fill 和 outline 依然有三种表示颜色的方式:
outline=1, fill=1 (直接赋值)
outline='red', fill='blue' (表明字符串)
outline='#0EFF12', fill='#000000' (十六进制颜色,Color Hex)
实例:
白色背景(size = 200 * 200)勾画出四个点的轮廓 (blue) 后再填充 (red)
import numpy as np
from PIL import Image, ImageDraw
xy = [(30, 30), (180, 30), (180, 180), (30, 180)]
img = Image.new("RGB", [200, 200], 'white')
img1 = ImageDraw.Draw(img)
img1.polygon(xy, fill="red", outline="blue")
img.show()
输出:

参考:
“https://vimsky.com/examples/usage/python-pil-imagedraw-draw-polygon-method.html”
PIL中polygon参数outline和fill理解