我有图像和蓝色像素列表。我想遍历蓝色像素,将它们更改为红色,并由此生成gif。因此,它一定是一条线,因此颜色从蓝色变为红色,但是出了问题
im = Image.open(r"test2.png")
pixels = im.load()
images = []
blues = get_sorted_blues() # See func below
for x, y in blues:
...: pixels[x, y] = (255, 0, 0)
...: images.append(im)
images[0].save('result.gif',
...: save_all=True,
...: append_images=images[1:],
...: duration=100,
...: loop=0)
def get_sorted_blues():
...: blues = []
...: for x in range(im.width):
...: for y in range(im.height):
...: if pixels[x, y] == (0, 0, 255):
...: blues.append([x, y])
...: return sorted(blues)
result.gif它只是一条红线,没有任何动画