You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用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帧对比图

原图片及GIF帧对比
原图片及GIF帧对比
原图片及GIF帧对比
原图片及GIF帧对比
原图片及GIF帧对比
原图片及GIF帧对比
原图片及GIF帧对比
原图片及GIF帧对比
原图片及GIF帧对比
原图片及GIF帧对比
原图片及GIF帧对比
原图片及GIF帧对比

内容的提问来源于stack exchange,提问作者이수현

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.04 05:02:40