【问题标题】:How do you make a progress bar and put it on an image?您如何制作进度条并将其放在图像上?
【发布时间】:2021-03-31 10:40:37
【问题描述】:

我正在尝试在图像上添加进度条。

我有一个不和谐的机器人,它的关卡系统是这样的:

现在我想做的是将级别作为进度条,满分 20。一旦达到 20,新目标将是 40。

我曾尝试寻找教程和阅读网站,但找不到任何关于在图像上放置进度条的信息。

我的最终目标是这样的(我从 MEE6 得到这个):

有没有办法使用 Python 和枕头或其他模块来做到这一点?

【问题讨论】:

  • 请以here为起点,了解如何使用PIL绘图
  • 绘画能让我做什么?
  • 你会画画!?!
  • 嗯,这很明显......哈哈

标签: python


【解决方案1】:

您可以通过以下方式绘制自己的进度:

from PIL import Image, ImageFont, ImageDraw, ImageEnhance

def drawProgressBar(d, x, y, w, h, progress, bg="black", fg="red"):
    # draw background
    d.ellipse((x+w, y, x+h+w, y+h), fill=bg)
    d.ellipse((x, y, x+h, y+h), fill=bg)
    d.rectangle((x+(h/2), y, x+w+(h/2), y+h), fill=bg)

    # draw progress bar
    w *= progress
    d.ellipse((x+w, y, x+h+w, y+h),fill=fg)
    d.ellipse((x, y, x+h, y+h),fill=fg)
    d.rectangle((x+(h/2), y, x+w+(h/2), y+h),fill=fg)

    return d

# create image or load your existing image with out=Image.open(path)
out = Image.new("RGB", (150, 100), (255, 255, 255))
d = ImageDraw.Draw(out)

# draw the progress bar to given location, width, progress and color
d = drawProgressBar(d, 10, 10, 100, 25, 0.5)
out.save("output.jpg")

这将创建如下内容:

有关绘图的更多详细信息,请查看documentation,您可以在其中找到一些示例,例如添加文字等等...

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-09-14
    • 2011-02-28
    • 1970-01-01
    • 1970-01-01
    • 2023-03-29
    • 1970-01-01
    • 2012-04-30
    • 1970-01-01
    相关资源
    最近更新 更多