Last active
March 16, 2016 21:20
-
-
Save margusmartsepp/c1fe3e4a51bfded8e501 to your computer and use it in GitHub Desktop.
Png images to gif
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
http://www.codeproject.com/Articles/11505/NGif-Animated-GIF-Encoder-for-NET