我在python中有一个2d列表,我想制作数据的图形图片.也许是一个m列的网格,其中每个方格是不同的灰色,具体取决于我的2d列表中的值.
但是,我似乎无法弄清楚如何使用PIL创建图像.这是我一直在搞乱的一些东西:
def createImage(): img = Image.new('L', (100,100), 'white') img.save('test.bmp') for i in range(0,15): for j in range(0,15): img.putpixel((i,j), (255,255,255))
但是,我收到一个错误,说需要一个整数(与putpixel一致的问题)
这是来自http://en.wikibooks.org/wiki/Python_Imaging_Library/Editing_Pixels:
from PIL import Image img = Image.new( 'RGB', (255,255), "black") # Create a new black image pixels = img.load() # Create the pixel map for i in range(img.size[0]): # For every pixel: for j in range(img.size[1]): pixels[i,j] = (i, j, 100) # Set the colour accordingly img.show()