使用Python Pillow/Imageio生成GIF时颜色丢失的问题求助
PNG转GIF丢失颜色问题求助
我计划将360张间隔1度的灯泡气压PNG图片合成为GIF,但使用Pillow生成后发现GIF丢失了原图片的颜色。怀疑是Pillow的问题,改用Imageio尝试后仍出现相同问题,不知道该怎么解决。
我的实现代码
Imageio版本代码
import matplotlib.pyplot as plt import os import numpy as np import imageio from PIL import Image import matplotlib.image as mpimg file_list = os.listdir("./") file_png = [file for file in file_list if file.endswith(".png")] path = [f"./{i}" for i in file_png] paths = [Image.open(i) for i in path] imageio.mimsave('./simul2.gif', paths, fps = 60)
Pillow版本代码
import numpy as np from PIL import Image al = [] for i in np.arange(0, 360, 1): st = "{}.png".format(i) al.append(st) frames = [] for j in al: new_frame = Image.open(j) frames.append(new_frame) frames[0].save('simul1.gif', format = 'GIF', append_images = frames[1:], save_all = True, duration = 1, loop = 0)
原图片与生成的GIF帧对比图












内容的提问来源于stack exchange,提问作者이수현
相关产品推荐
相关产品推荐

