使用PIL paste 直接粘贴透明图片时Alpha通道不会被粘贴...

# 方法 1
# 底图
im = Image.open(file).convert("RGBA")
# 贴图
icon = Image.open(file).convert("RGBA")
r, g, b, a = icon.split()
im.paste(icon, (100, 100), mask=a)
im.show

# 方法2
background = Image.open("test1.png")
foreground = Image.open("test2.png")

background.paste(foreground, (0, 0), foreground)
background.show()

查看 This 以及 官方文档

最后修改:2022 年 03 月 13 日
如果觉得我的文章对你有用,请随意赞赏