gpt4 book ai didi

python - 如何将从元组列表创建的 png 图像转换回该元组列表?

转载 作者:行者123 更新时间:2023-11-28 22:23:00 24 4
gpt4 key购买 nike

tupledlist=[(71, 146, 110), (71, 146, 98), (71, 146, 99), (71, 146, 109), (71, 146, 26), ( 71, 146, 99), (71, 146, 109), (71, 146, 26), (71, 146, 91), (71, 146, 26), (71, 146, 110), (71, 146, 95), (71, 146, 109), (71, 146, 110), (71, 146, 26), (71, 146, 103), (71, 146, 95), (71, 146, 109), (71, 146, 109), (71, 146, 91), (71, 146, 97), (71, 146, 95), (71, 146, 26), (71, 146, 91) , (71, 146, 104), (71, 146, 94), (71, 146, 26), (71, 146, 110), (71, 146, 98), (71, 146, 99), ( 71, 146, 109), (71, 146, 26), (71, 146, 99), (71, 146, 109), (71, 146, 26), (71, 146, 91), (71, 146, 26), (71, 146, 110), (71, 146, 95), (71, 146, 109), (71, 146, 110), (71, 146, 26), (71, 146, 102), (71, 146, 99), (71, 146, 109), (71, 146, 110)]

from PIL import Image
OUTPUT_IMAGE_SIZE = (1280, 720)
for frame_number, color in enumerate(tupledlist):
image = Image.new('RGB', OUTPUT_IMAGE_SIZE, color=color)
image.save("path.png")

这将创建一个 png 图像。现在我想要返回图像中的元组列表。如何做到这一点?我尝试了 image.getbands() 但它不起作用。

import PIL
from PIL import Image
image=Image.open("c:/users/ashub/desktop/encrypted.png")
image.getbands()

最佳答案

如果我没理解错的话,你想实现这个:

from PIL import Image

tupledlist=[(71, 146, 110), (71, 146, 98), (71, 146, 99), (71, 146, 109), (71, 146, 26), (71, 146, 99), (71, 146, 109), (71, 146, 26), (71, 146, 91), (71, 146, 26),
(71, 146, 110), (71, 146, 95), (71, 146, 109), (71, 146, 110), (71, 146, 26), (71, 146, 103), (71, 146, 95), (71, 146, 109), (71, 146, 109), (71, 146, 91), (71, 146, 97),
(71, 146, 95), (71, 146, 26), (71, 146, 91), (71, 146, 104), (71, 146, 94), (71, 146, 26), (71, 146, 110), (71, 146, 98), (71, 146, 99), (71, 146, 109), (71, 146, 26),
(71, 146, 99), (71, 146, 109), (71, 146, 26), (71, 146, 91), (71, 146, 26), (71, 146, 110), (71, 146, 95), (71, 146, 109), (71, 146, 110), (71, 146, 26), (71, 146, 102),
(71, 146, 99), (71, 146, 109), (71, 146, 110)]

OUTPUT_IMAGE_SIZE = (1280, 720)
image = Image.new('RGB', OUTPUT_IMAGE_SIZE)
image.putdata(tupledlist)
image.save("path.png")
print("Saved image.")

image=Image.open("path.png")
print(list(image.getdata()))

具有 RGB 值的列表将存储在图像中,但剩余的其余像素将采用 RGB 值 (0,0,0)。打印它们将显示所有 921600 (1280x720) 像素。

关于python - 如何将从元组列表创建的 png 图像转换回该元组列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47333949/

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