moe*_*eth 3 python python-imaging-library
如何在ImageDraw中绘制圆角线?
我可以用
draw.line((x, y, x1, y1), width=4)
Run Code Online (Sandbox Code Playgroud)
但是线条角不是圆形的,它们是平直的。
PIL/Pillow 中的图形绘制基元非常基础,不会像pycairo(教程和示例)这样的专用图形绘制包那样做漂亮的斜角、米、抗锯齿和圆角。
话虽如此,您可以通过在线条末端绘制圆圈来模拟线条上的圆角边缘:
from PIL import Image, ImageDraw
im = Image.new("RGB", (640, 240))
dr = ImageDraw.Draw(im)
def circle(draw, center, radius, fill):
dr.ellipse((center[0] - radius + 1, center[1] - radius + 1, center[0] + radius - 1, center[1] + radius - 1), fill=fill, outline=None)
W = 40
COLOR = (255, 255, 255)
coords = (40, 40, 600, 200)
dr.line(coords, width=W, fill=COLOR)
circle(dr, (coords[0], coords[1]), W / 2, COLOR)
circle(dr, (coords[2], coords[3]), W / 2, COLOR)
im.show()
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1767 次 |
| 最近记录: |