访问量: 9 次浏览
ImageDraw.Draw.pieslice()PIL 是 Python 成像库,它为 Python 解释器提供了图像编辑功能。ImageDraw 模块为图像对象提供简单的 2D 图形。你可以使用这个模块来创建新的图像,注释或修饰现有的图像,并为网络使用而即时生成图形。
ImageDraw.Draw.pieslice() 与圆弧相同,但也在端点和边界框中心之间绘制直线。
语法:
PIL.ImageDraw.Draw.pieslice(xy, start, end, fill=None, outline=None)
参数:
xy – 四个点来定义边界框。序列为 [(x0, y0), (x1, y1)] 或 [x0, y0, x1, y1]。start – 起始角度,单位是度。角度从 3 点钟方向开始测量,顺时针增加。end – 结束的角度,单位是度。fill – 用于填充的颜色。outline – 轮廓使用的颜色。返回: 饼状的图像对象。
# 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()
输出:
