该函数用于画椭圆。
函数原型ellipse(xy, fill=None, outline=None)
第一参数为椭圆的外切矩形, 当外切矩形是正方形时,形状为圆。xy指(x1, y1, x2, y2)
可以看成是(left, top, right, bottom)
第二、三参数为填充颜色和线条颜色。
from PIL import Image
from PIL import ImageDraw
image = Image.open('1.jpg')
draw = ImageDraw.Draw(image)
draw.ellipse((590, 260, 620, 290), 'red')
image.show()
参考文献:
https://blog.csdn.net/guduruyu/article/details/71213717
所有颜色:
import matplotlib.pyplot as plt
import matplotlib.patches as patches
import matplotlib.colors as colors
import math
fig = plt.figure()
ax = fig.add_subplot(111)
ratio = 1.0 / 3.0
count = math.ceil(math.sqrt(len(colors.cnames)))
x_count = count * ratio
y_count = count / ratio
x = 0
y = 0
w = 1 / x_count
h = 1 / y_count
for c in colors.cnames:
pos = (x / x_count, y / y_count)
ax.add_patch(patches.Rectangle(pos, w, h, color=c))
ax.annotate(c, xy=pos)
if y >= y_count-1:
x += 1
y = 0
else:
y += 1
plt.show()