我有这些:
pixels = [(255, 255, 255, 0), (255, 255, 255, 0), (255, 255, 255, 0), (255, 255, 255, 0), (255, 255, 255, 0), (204, 204, 204, 255), (204, 204, 204, 255), (119, 119, 119, 255), (119, 119, 119, 255), (204, 204, 204, 255), (204, 204, 204, 255), (255, 255, 255, 0), (255, 255, 255, 0), (255, 255, 255, 0), (255, 255, 255, 0), (255, 255, 255, 0)......]
这是一个包含大量tuple
s的列表,我想将其转换为图片。
我无法找到任何解决方案。
答案 0 :(得分:1)
您可以使用Python Imaging Library作为替代方案,将数组转换为图片:
from PIL import Image
pixels = [(255, 255, 255, 0), (255, 255, 255, 0), (255, 255, 255, 0), (255, 255, 255, 0), (255, 255, 255, 0), (204, 204, 204, 255), (204, 204, 204, 255), (119, 119, 119, 255), (119, 119, 119, 255), (204, 204, 204, 255), (204, 204, 204, 255), (255, 255, 255, 0), (255, 255, 255, 0), (255, 255, 255, 0), (255, 255, 255, 0), (255, 255, 255, 0)......]
#Sample values of width and height. Change them according to your needs.
size = (50,50)
fileName = "image.png"
image = Image("RGBA",size)
image.putdata(pixels)
image.save(fileName)
答案 1 :(得分:0)