Python PIL | ImageDraw.Draw.arc()
PIL 是Python Imaging Library,它为Python解释器提供了图像编辑功能。 ImageDraw
模块为 Image 对象提供简单的 2D 图形。您可以使用此模块创建新图像、注释或修饰现有图像,以及动态生成图形以供 Web 使用。
ImageDraw.Draw.arc()
在给定边界框内的起始角和结束角之间绘制弧线(圆形轮廓的一部分)。
Syntax: PIL.ImageDraw.Draw.ellipse(xy, fill=None, outline=None)
Parameters:
xy – Four points to define the bounding box. Sequence of [(x0, y0), (x1, y1)] or [x0, y0, x1, y1].
start – Starting angle, in degrees. Angles are measured from 3 o’clock, increasing clockwise.
end – Ending angle, in degrees.
fill – Color to use for the arc.
Returns: An Image object in arc shape.
# 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 rectangle image
img1 = ImageDraw.Draw(img)
img1.arc(shape, start = 20, end = 130, fill ="pink")
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 rectangle image
img1 = ImageDraw.Draw(img)
img1.arc(shape, start = 20, end = 130, fill ="red")
img.show()
输出: