【发布时间】:2020-08-14 15:40:16
【问题描述】:
【问题讨论】:
标签: python image python-imaging-library
【问题讨论】:
标签: python image python-imaging-library
我不确定你应该如何编写代码,但我想如果我在进度条的右端画一个青色圆圈,然后从左边填充它,它应该可以工作:
#!/usr/bin/env python3
from PIL import Image, ImageDraw
# Open template and get drawing context
im = Image.open('progress.png').convert('RGB')
draw = ImageDraw.Draw(im)
# Cyan-ish fill colour
color=(98,211,245)
# Draw circle at right end of progress bar
x, y, diam = 254, 8, 34
draw.ellipse([x,y,x+diam,y+diam], fill=color)
# Flood-fill from extreme left of progress bar area to behind circle
ImageDraw.floodfill(im, xy=(14,24), value=color, thresh=40)
# Save result
im.save('result.png')
为了让你明白我在做什么,我在下面的图片标记为红色的地方画了一个圆圈,然后从图片标记为黄色的地方开始填充:
因此,如果您想显示更多进度,只需在代码中增加x - 如果您想减少进度,请减少x。
关于圆形末端的质量,如果您从半径为 17 的圆开始并将其放大,您肯定会得到锯齿状边缘。以下是 ImageMagick 的作用,左边有抗锯齿,右边没有:
关键字:Python、图像处理、PIL、Pillow、progress、bar、progress-bar、圆角。
【讨论】:
x,y 坐标并将它们放入代码中。然后对红色矩形的左上角执行相同的操作。将矩形的直径设置为你想要的圆的高度(即直径),并根据要显示的进度设置x。