Skip to content

Instantly share code, notes, and snippets.

@margusmartsepp
Last active March 16, 2016 21:20
Show Gist options
  • Save margusmartsepp/c1fe3e4a51bfded8e501 to your computer and use it in GitHub Desktop.
Save margusmartsepp/c1fe3e4a51bfded8e501 to your computer and use it in GitHub Desktop.
Png images to gif
using System;
using System.Drawing;
using Gif.Components;
using System.Collections.Generic;
namespace Example
{
class ExampleMain
{
[STAThread]
static void Main(string[] args)
{
var path = @"C:\Users\Margus\Documents\visual studio 2015\Projects\ConwaysGameOfLife\ConwaysGameOfLife\bin\Debug\";
var list = new List<string>();
for (int i = 1; i < 21; i++)
{
list.Add($"{path}GoL_12_34_51_700_{i}.png");
}
var imageFilePaths = list.ToArray();
var outputFilePath = path + "test.gif";
AnimatedGifEncoder e = new AnimatedGifEncoder();
e.Start(outputFilePath);
e.SetDelay(500);
//-1:no repeat,0:always repeat
e.SetRepeat(0);
for (int i = 0, count = imageFilePaths.Length; i < count; i++)
{
e.AddFrame(Image.FromFile(imageFilePaths[i]));
Console.WriteLine(i);
}
e.Finish();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment