A .NET library for creating and reading animated GIF files. This is a C# port of the popular animated-gif-lib-for-java library, providing robust support for GIF encoding and decoding and frame management. Ideal for applications requiring animated GIF generation from images or extraction of frames from existing GIFs.
$ dotnet add package Openize.Animated-GIFA .NET library for creating and reading animated GIF files. This is a C# port of the popular animated-gif-lib-for-java library, providing robust support for GIF encoding and decoding with advanced features like color quantization, transparency control, and frame management.
dotnet add package Openize.Animated.GIF
Or via NuGet Package Manager:
Install-Package Openize.Animated.GIF
using Openize.Animated.GIF;
using System.Drawing;
// Initialize the encoder
var encoder = new AnimatedGifEncoder();
encoder.Start("output.gif");
// Configure animation settings
encoder.SetDelay(500); // 500ms between frames
encoder.SetRepeat(0); // Loop infinitely
// Add frames
encoder.AddFrame(new Bitmap("frame1.png"));
encoder.AddFrame(new Bitmap("frame2.png"));
// Finish encoding
encoder.Finish();
// Initialize the decoder
var decoder = new GifDecoder();
decoder.Read("input.gif");
// Get information
int frameCount = decoder.GetFrameCount();
int loopCount = decoder.GetLoopCount(); // 0 = infinite
// Extract frames
for (int i = 0; i < frameCount; i++)
{
Bitmap frame = decoder.GetFrame(i);
frame.Save($"frame_{i}.png");
}
// Configure transparency
encoder.SetTransparent(Color.White, true); // Exact match
// Set specific background color
encoder.SetBackground(Color.Black);
// Custom size (for oversized images)
encoder.SetSize(800, 600);
This library uses System.Drawing.Common which has some limitations on non-Windows platforms. For production use on Linux or macOS, you may need to install additional dependencies:
apt-get install libgdiplusbrew install mono-libgdiplusOpenize.Animated-GIF for .NET is licensed under the Apache License 2.0.
[!CAUTION] Openize does not and cannot grant You a patent license for the utilization of animated-gif-lib-for-java compression/decompression technologies.
Feel free to submit issues and enhancement requests!
This library is a C# port of animated-gif-lib-for-java by Roberto Tyley, ported and maintained by Openize Pty Ltd.
Sample files used for tests and located in the "./testdata/" folder belong to animated-gif-lib-for-java and are used according to Apache License 2.0.
For more information and documentation, visit Openize.com.