网上找的代码,无法得到正确结果,无语了。
合成图片为gif程序代码:
import imageio import os def create_gif(img_dir, image_list, gif_name, duration=0.05): frames = [] for image_name in image_list: print("image_name={0} img_dir={1}".format(image_name, img_dir)) frames.append(imageio.imread(img_dir + '/'+ image_name)) imageio.mimsave(gif_name, frames, 'GIF', duration=duration) return def main(): img_dir = 'C:/Users/Admin/Desktop/1' duration = 0.05 # 每秒20帧 image_list = os.listdir(img_dir + '/') gif_name = 'new.gif' create_gif(img_dir, image_list, gif_name, duration) if __name__ == '__main__': main()
程序代码:
import imageio import os import os.path as osp imgpath="C:/Users/Admin/Desktop/1" frames=[] for idx in sorted(os. listdir(imgpath)): img=osp. join(imgpath, idx) frames.append(imageio. imread(img)) imageio.mimsave("chenge.gif",frames,'GIF',duration=0.1)