在PIL中绘制半透​​明多边形 [英] Drawing semi-transparent polygons in PIL

查看:327
本文介绍了在PIL中绘制半透​​明多边形的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用 Python Imaging Library 绘制半透明多边形?

How do you draw semi-transparent polygons using the Python Imaging Library?

推荐答案

您可以在单独的RGBA图像上绘制多边形,然后使用 Image.paste(图像,框,蒙版)方法?

Can you draw the polygon on a separate RGBA image then use the Image.paste(image, box, mask) method?

编辑:此方法有效。

from PIL import Image
from PIL import ImageDraw
back = Image.new('RGBA', (512,512), (255,0,0,0))
poly = Image.new('RGBA', (512,512))
pdraw = ImageDraw.Draw(poly)
pdraw.polygon([(128,128),(384,384),(128,384),(384,128)],
              fill=(255,255,255,127),outline=(255,255,255,255))
back.paste(poly,mask=poly)
back.show()

http://effbot.org/imagingbook/image.htm#image-paste-method

这篇关于在PIL中绘制半透​​明多边形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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