gpt4 book ai didi

Python Image Library - 使图像区域透明

转载 作者:太空宇宙 更新时间:2023-11-03 13:21:32 24 4
gpt4 key购买 nike

我有一个简短的问题要问比我更了解 Python 图像库的人。我有一个带有 alpha channel 的 png 图像,我希望前两行像素完全透明。就是这样!到目前为止,我的努力使前两行透明,但原始图像丢失了它的 alpha channel 信息。有人知道实现此目标的最佳方法吗?

最佳答案

你可以这样做。

img = Image.open("withAlpha.png")
p = img.load()

for y in range(2):
for x in range(img.size[0]):
t = list(p[x,y])
t[3] = 0
p[x,y] = tuple(t)

img.save("result.png")

关于Python Image Library - 使图像区域透明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12228829/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com