python - 在ImageDraw python中绘制圆角线

标签 python python-imaging-library

enter image description here

如何在ImageDraw中绘制圆角线?

我会画画

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

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

最佳答案

PIL/Pillow 中的图形绘制基元非常基本,不会像 pycairo 这样的专用图形绘制包那样做漂亮的斜角、米、抗锯齿和圆角边缘。 (tutorial 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()

关于python - 在ImageDraw python中绘制圆角线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33076575/

相关文章:

python - 对于列表 : del n 中的 n

python - 使页面上所有子图的 x 轴长度相同

python - Selenium python 单击按钮

python - 找不到满足要求的版本 Pillow==2.7.0

Python PIL 图像验证返回无

python - 使用 Python/PIL 或类似工具来缩小空格

python - 如何在网络上的Python Flask中从AWS s3读取文件

python - 基于列表的Python注释C定义

image-processing - 有什么比 ImageMagick 更快的吗?

python - 为什么python PIL不能在一个程序中显示两个图像