我试图创建一个Perlin噪声应用程序,它随机生成一个游戏地图。我正在尝试写入新图像,但只有第一行正在写入。Pillow/PIL Python - 只写入图像的第一行
这里是我创建了一个存根表现出了同样的问题:
from PIL import Image
from random import randint
height = 25
width = 25
z = randint(-1000, 1000)/100
img = Image.new('RGBA', (width, height), color=(255, 255, 255, 255))
for y in range(height):
img.putdata([(0,255,0,255) for x in range(width)]) # Logic error occurs on this line
img.save("location.png", "PNG")
什么愚蠢的错误我在做这个时间呢?
'Image.putdata()'想要整个图像的数据在一个序列中;它不支持分块构建图像。 – jasonharper
你可以用putpixel代替putdata,但这可能会很慢。如果您试图将图像的某个区域设置为相同的值,则可以使用“ImageDraw”模块的功能,例如, 'ImageDraw.Draw.rectangle()'。 – ahota