开发者

How to build an image object in PIL/Python

I have a list of 3-item tuples that is the result of list(PIL.Image.getdata()).

How do I do开发者_运维技巧 the opposite: build a PIL.Image object from this list?


The output of getdata() does not include the image format or the size, so you'll need to preserve those (or get the information some other way). Then do this, using the putdata() method:

# 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)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜