PIL是Python Imaging Library,它為python解釋器提供了圖像編輯函數。的ImageDraw
模塊為Image對象提供簡單的2D圖形。您可以使用該模塊來創建新圖像,注釋或修飾現有圖像,以及即時生成圖形以供Web使用。
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-用於輪廓的顏色。
返回:切片形狀的Image對象。
# 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()
輸出:
相關用法
注:本文由純淨天空篩選整理自Sunitamamgai大神的英文原創作品 Python PIL | ImageDraw.Draw.pieslice()。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。