I was curious as to how to create an animated .gif in C# using the imagemagick library class. This is what i am using so far:
using (MagickImageCollection collection = new MagickImageCollection())
{
//collection.CacheDirectory = @"C:\MyProgram\MyTempDir";
// Add first image and set the animation delay to 100ms
//MagickNET.Initialize(@"C:\Users\johsam\Downloads\Magick\MagickScript.xsd");
collection.Add("Koala.jpg");
collection[0].AnimationDelay = 1;
// Add second image, set the animation delay to 100ms and flip the image
collection.Add("Desert.jpg");
collection[1].AnimationDelay = 100;
collection[1].Flip();
// Optionally reduce colors
QuantizeSettings settings = new QuantizeSettings();
settings.Colors = 256;
collection.Quantize(settings);
// Optionally optimize the images (images should have the same size).
collection.Optimize();
// Save gif
collection.Write("test.Animated.gif");
}
The issue is that although it creates a .gif there is no moving image when you open it. How do you go about stringing the images together to create a moving image?
The code you are using, appears to be the example provided with the codeplex site. The logic appears to work as intended, but my presumption is that the animation delay, on the initial image in the collection, is too small (1 ms). You would arguably only see the second image. Please increase your animation delay (to 100ms), and confirm. Once completed, you can adjust the delay appropriately, to an interval that produces the desired output.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With