📜  Python PIL | ImageDraw.Draw.pieslice()

📅  最后修改于: 2022-05-13 01:55:34.958000             🧑  作者: Mango

Python PIL | ImageDraw.Draw.pieslice()

PIL 是Python Imaging Library,它为Python解释器提供了图像编辑功能。 ImageDraw模块为 Image 对象提供简单的 2D 图形。您可以使用此模块创建新图像、注释或修饰现有图像,以及动态生成图形以供 Web 使用。

ImageDraw.Draw.pieslice()和 arc 一样,但也在端点和边界框的中心之间绘制直线。

# importing image object from PIL
import math
from PIL import Image, ImageDraw
   
w, h = 220, 190
shape = [(40, 40), (w - 10, h - 10)]
   
# creating new Image object
img = Image.new("RGB", (w, h))
   
# create pieslice image
img1 = ImageDraw.Draw(img)  
img1.pieslice(shape, start = 50, end = 250, fill ="# ffff33", outline ="red")
img.show()

输出:

另一个例子:这里我们使用不同的颜色进行填充。

# importing image object from PIL
import math
from PIL import Image, ImageDraw
   
w, h = 220, 190
shape = [(40, 40), (w - 10, h - 10)]
   
# creating new Image object
img = Image.new("RGB", (w, h))
   
# create pieslice image
img1 = ImageDraw.Draw(img)  
img1.pieslice(shape, start = 50, end = 250, fill ="# 800080", outline ="white")
img.show()

输出: