在ImageDraw python中绘制圆角线

2024-06-23 20:03:57 发布

您现在位置:Python中文网/ 问答频道 /正文

enter image description here

如何在图像角上画圆线?在

我可以用

draw.line((x, y, x1, y1), width=4)

但是线条的角不是圆的,而是直的。在


Tags: 图像linewidth线条x1drawy1画圆
1条回答
网友
1楼 · 发布于 2024-06-23 20:03:57

PIL/Pillow中的图形绘制原语是非常基本的,不会像pycairotutorial and examples)那样做很好的斜角、米、抗锯齿和圆角。在

也就是说,您可以通过在线条末端绘制圆来模拟线条上的圆角:

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()

相关问题 更多 >

    热门问题