python - Pillow 无法正确保存图像(Python 2.7)

标签 python python-imaging-library

我有以下代码:

out_image = Image.new('RGBA', (1024,600))
cur_color = (255,255,255,0)


for t in range(0, 100):
    out_image.putpixel((50,t),cur_color)
out_image.show()
out_image.save("test.png")

out_image.show() 显示像素正确放置的图像,但是 test.png 被保存为空白图像。

最佳答案

我相信 show() 正在工作,因为它首先创建一个临时位图用于显示。位图没有透明度,因此这表明您的问题与透明度有关。

使用255:

cur_color = (255,255,255,255)  # instead of (255,255,255, 0)

关于python - Pillow 无法正确保存图像(Python 2.7),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33093213/

相关文章:

python - 循环图像,保存ID名称并将其相应地存储在数据框中

python - 在 Python PIL 中合并图像以生成动画 gif

python - Requests.get() 函数给出的结果与 webbrowser.open() 函数不同

python - json 如何将 None 转储为空字符串

python-3.x - 如何将 ImageTk 转换为图像?

python - 如何使用 Python 图像库(PIL/Pillow)检测图像是否为渐进式 JPEG?

python - python类中的属性

python - 删除多索引数据框中具有重复索引的行

python - 如何过滤字符串?

python - 使用 PIL 将一张图片复制到另一张图片上