python - 用 PIL 在图像上画一条线

标签 python python-imaging-library

我想画一条线并显示出来。 假设我有一个 PIL 图像。

draw = ImageDraw.Draw(pilImage)
draw.line((100,200, 150,300), fill=128)

如何显示图像?在画线之前我可以这样做:

imshow(pilImage)

imshow(draw) 不显示图像。

如何将其转换回 PIL 图像?

最佳答案

这应该可行:

from PIL import Image, ImageDraw
im = Image.new('RGBA', (400, 400), (0, 255, 0, 255)) 
draw = ImageDraw.Draw(im) 
draw.line((100,200, 150,300), fill=128)
im.show()

基本上使用 ImageDraw 绘制图像,然后在更改后显示该图像,以绘制粗线通过宽度

draw.line((100,200, 150, 300), fill=128, width=3)

关于python - 用 PIL 在图像上画一条线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13053443/

相关文章:

python - 从 numpy 数组访问 block

python - 有没有办法从python gdata youtube客户端中的YouTubePlayListVideoEntry获取YouTubeVideoEntry?

python - 对直方图进行颜色编码

python - 在 python 中为大文件创建校验和的最快方法

python - 使用 OpenCV 将一定范围内的颜色更改为另一种颜色

python - git ls-files 脚本如何工作

python - 使用 Python 编辑动画 gif 标题循环值

python - Django 中图像/头像的自定义保存方法 - 如何使用

python - PIL : can't save the jpg pasted with a png

python - PIL 值错误 : not enough image data?