小编Mar*_*eur的帖子

PIL中的透明PNG结果不透明

我一直在墙上撞了一会儿,所以也许有人可以提供帮助.

我正在使用PIL打开一个带有透明背景和一些随机黑色涂鸦的PNG,并尝试将其置于另一个PNG(没有透明度)的顶部,然后将其保存到第三个文件.

它最后都是黑色的,这很刺激,因为我没有说它是黑色的.

我已经使用其他帖子中的多个提议修复对此进行了测试.图像以RGBA格式打开,它仍然搞砸了.

此外,该程序应该处理各种文件格式,这就是我使用PIL的原因.讽刺的是,我试过的第一种格式都是搞砸了.

任何帮助,将不胜感激.这是代码:

from PIL import Image
img = Image.open(basefile)
layer = Image.open(layerfile) # this file is the transparent one
print layer.mode # RGBA
img.paste(layer, (xoff, yoff)) # xoff and yoff are 0 in my tests
img.save(outfile)
Run Code Online (Sandbox Code Playgroud)

python png transparent python-imaging-library

23
推荐指数
1
解决办法
1万
查看次数

标签 统计

png ×1

python ×1

python-imaging-library ×1

transparent ×1