用PIL在图像上画一条线 [英] drawing a line on an image with PIL

查看:136
本文介绍了用PIL在图像上画一条线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想画一条线并显示它. 假设我有一个PIL图片.

I want to draw a line and show it. assume I have a PIL image.

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

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

How can I show the image? Before drawing the line I could do:

imshow(pilImage)

imshow(draw)不显示图像.

如何将其转换回PIL图像?

How do I convert this back to a PIL image?

推荐答案

这应该有效:

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

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

Basically using ImageDraw draw over the image, then display that image after changes, to draw a thick line pass width

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

这篇关于用PIL在图像上画一条线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆