如何在PIL/Python中构建图像对象

Ale*_*der 6 python image python-imaging-library

我有一个列表的三项元组列表(PIL.Image.getdata()).

我该怎么做:从这个列表中构建一个PIL.Image对象?

Pet*_*sen 9

输出getdata()不包括图像格式或大小,因此您需要保留它们(或以其他方式获取信息).然后使用以下putdata()方法执行此操作:

# get data from old image (as you already did)
data = list(oldimg.getdata())

# create empty new image of appropriate format
newimg = Image.new(format, size)  # e.g. ('RGB', (640, 480))

# insert saved data into the image
newimg.putdata(data)
Run Code Online (Sandbox Code Playgroud)