python pil 给图片添加一个半透明的效果

from PIL import Image, ImageDraw
bg_img =Image.open('./Morning.png')
# bg_img = Image.new("RGBA", (256, 256), (0, 0, 255, 255))
def drawRect(img, pos, **kwargs):
    transp = Image.new('RGBA', img.size, (0,0,0,0))
    draw = ImageDraw.Draw(transp, "RGBA")
    draw.rectangle(pos, **kwargs)
    img.paste(Image.alpha_composite(img, transp))

drawRect(bg_img, (0,155,875,435), fill=(255,255,255,150))
bg_img.show()

这是原图

上一篇:2014.3.5-C语言学习小结


下一篇:元胞自动机