如何使用RGB元组列表在PIL中创建图像? [英] How do I create an image in PIL using a list of RGB tuples?
本文介绍了如何使用RGB元组列表在PIL中创建图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设我在一个看起来像list(im.getdata())
的列表中有一个像素列表(表示为具有3个RGB值的元组),如下所示:
Suppose I have a list of pixels (represented as tuples with 3 RGB values) in a list that looks like list(im.getdata())
, like this:
[(0,0,0),(255,255,255),(38,29,58)...]
如何使用这种格式的RGB值(每个元组对应一个像素)来创建新图像?
How do I create a new image using RGB values (each tuple corresponds to a pixel) in this format?
感谢您的帮助.
推荐答案
您可以这样做:
list_of_pixels = list(im.getdata())
# Do something to the pixels...
im2 = Image.new(im.mode, im.size)
im2.putdata(list_of_pixels)
这篇关于如何使用RGB元组列表在PIL中创建图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文