
- Python Pillow 教程
- Python Pillow - 首頁
- Python Pillow - 概述
- Python Pillow - 環境設定
- 基本影像操作
- Python Pillow - 影像處理
- Python Pillow - 調整影像大小
- Python Pillow - 翻轉和旋轉影像
- Python Pillow - 裁剪影像
- Python Pillow - 為影像新增邊框
- Python Pillow - 識別影像檔案
- Python Pillow - 合併影像
- Python Pillow - 剪下和貼上影像
- Python Pillow - 滾動影像
- Python Pillow - 在影像上寫入文字
- Python Pillow - ImageDraw 模組
- Python Pillow - 合併兩張影像
- Python Pillow - 建立縮圖
- Python Pillow - 建立水印
- Python Pillow - 影像序列
- Python Pillow 顏色轉換
- Python Pillow - 影像上的顏色
- Python Pillow - 建立彩色影像
- Python Pillow - 將顏色字串轉換為 RGB 顏色值
- Python Pillow - 將顏色字串轉換為灰度值
- Python Pillow - 透過更改畫素值來更改顏色
- 影像處理
- Python Pillow - 降噪
- Python Pillow - 更改影像模式
- Python Pillow - 影像合成
- Python Pillow - 使用 Alpha 通道
- Python Pillow - 應用透視變換
- 影像濾鏡
- Python Pillow - 為影像新增濾鏡
- Python Pillow - 卷積濾鏡
- Python Pillow - 模糊影像
- Python Pillow - 邊緣檢測
- Python Pillow - 浮雕影像
- Python Pillow - 增強邊緣
- Python Pillow - 不銳化掩膜濾鏡
- 影像增強和校正
- Python Pillow - 增強對比度
- Python Pillow - 增強銳度
- Python Pillow - 增強色彩
- Python Pillow - 校正色彩平衡
- Python Pillow - 去噪
- 影像分析
- Python Pillow - 提取影像元資料
- Python Pillow - 識別顏色
- 高階主題
- Python Pillow - 建立動畫 GIF
- Python Pillow - 批次處理影像
- Python Pillow - 轉換影像檔案格式
- Python Pillow - 為影像新增填充
- Python Pillow - 顏色反轉
- Python Pillow 與 NumPy 結合使用
- Python Pillow 與 Tkinter BitmapImage 和 PhotoImage 物件結合使用
- Image 模組
- Python Pillow - 影像混合
- Python Pillow 有用資源
- Python Pillow - 快速指南
- Python Pillow - 函式參考
- Python Pillow - 有用資源
- Python Pillow - 討論
Python Pillow - ImageDraw.rounded_rectangle() 函式
ImageDraw.rounded_rectangle() 方法用於繪製圓角矩形。矩形透過指定邊界框、角的半徑以及可選的填充顏色、輪廓顏色、線寬和每個角的圓角資訊來定義。
語法
以下是函式的語法:
ImageDraw.rounded_rectangle(xy, radius=0, fill=None, outline=None, width=1, corners=None)
引數
以下是此函式引數的詳細資訊:
xy - 它指定定義圓角矩形邊界框的兩個點。可以將其指定為兩個元組的序列 [(x0, y0), (x1, y1)] 或作為扁平列表 [x0, y0, x1, y1]。在這兩種情況下,都必須滿足條件 x1 >= x0 和 y1 >= y0。邊界框包含兩個端點。
radius - 圓角矩形的角半徑。
fill - 用於填充圓角矩形的顏色。
outline - 用於圓角矩形輪廓的顏色。
width - 圓角矩形輪廓的線寬(以畫素為單位)。預設值為 1。
corners - 一個元組,指示是否要圓角。元組格式為 (左上,右上,右下,左下)。此引數是關鍵字引數。
示例
示例 1
以下示例在指定的邊界框內繪製一個帶有圓角的圓角矩形,使用預設引數。
from PIL import Image, ImageDraw # Create a new image with a white background image = Image.new("RGB", (700, 300), "black") draw = ImageDraw.Draw(image) # Define the bounding box as a sequence of two tuples bounding_box = [(250, 30), (450, 270)] # Specify the radius for the rounded corners radius = 20 # Draw a rounded rectangle default parameters draw.rounded_rectangle(bounding_box, radius=radius) # Display the image image.show() print('The rounded rectangle is drawn successfully...')
輸出
The rounded rectangle is drawn successfully...
輸出影像

示例 2
此示例在指定的邊界框內繪製一個帶有圓角的圓角矩形,填充為淺藍色,輪廓為中等青綠色,並指定角的半徑。
from PIL import Image, ImageDraw # Create a new image with a white background image = Image.new("RGB", (700, 300), "white") draw = ImageDraw.Draw(image) # Define the bounding box as a sequence of two tuples bounding_box = [(250, 30), (450, 270)] # Specify the radius for the rounded corners radius = 50 # Specify fill and outline colors fill_color = "lightblue" outline_color = "mediumspringgreen" # Draw a rounded rectangle draw.rounded_rectangle(bounding_box, radius=radius, fill=fill_color, outline=outline_color, width=4) # Display the image image.show() print('The rounded rectangle is drawn successfully...')
輸出
The rounded rectangle is drawn successfully...
輸出影像

示例 3
以下示例演示如何在現有影像上使用不同的引數繪製圓角矩形。
from PIL import Image, ImageDraw # Open an Image image = Image.open('Images/TP-W.jpg') # Create the draw object draw = ImageDraw.Draw(image) # Define the bounding box as a sequence of two tuples bounding_box = [(245, 45), (445, 345)] # Specify the radius for the rounded corners radius = 40 # Draw a rounded rectangle with custom fill and outline colors draw.rounded_rectangle(bounding_box, radius=radius, outline="red", width=4) # Display the image image.show() print('The rounded rectangle is drawn successfully...')
輸出
The rounded rectangle is drawn successfully...
輸出影像

python_pillow_function_reference.htm
廣告