---
title: "Write Animated Gif"
canonical: https://www.graphicsmill.com/samples/Codecs/Gif/WriteAnimatedGif_cs
product: "Graphics Mill"
source: "Codecs/Gif/WriteAnimatedGif.cs"
---

# Write Animated Gif

Writes simple animated image in GIF format.

## Instruction

Create an animated GIF by generating multiple frames programmatically. Each frame should contain a green circle drawn at a different horizontal position on a yellow background. Use the memory-friendly Pipeline API to write the animation.

## Usings

```csharp
using Aurigma.GraphicsMill.Codecs;
using Aurigma.GraphicsMill.Drawing;
```

## Code Snippet

```csharp
using (var writer = new GifWriter("WriteAnimatedGif.gif"))
{
    writer.Width = 400;
    writer.Height = 100;
    writer.FrameOptions.Delay = 25;

    for (int i = 0; i < 400; i += 25)
    {
        var bitmap = new Bitmap(400, 100, PixelFormat.Format24bppRgb, RgbColor.Yellow);

        using (var graphics = bitmap.GetGraphics())
        {
            graphics.FillEllipse(new SolidBrush(RgbColor.Green), new System.Drawing.RectangleF(i, 0, 100, 100));
        }

        bitmap.ColorManagement.Convert(PixelFormat.Format8bppIndexed);

        Pipeline.Run(bitmap + writer);
    }
}
```

## Explanation

Here is a C# program that generates an animated GIF with a moving green circle on a yellow background:

This code creates an animated GIF `WriteAnimatedGif.gif` that is 400x100 pixels in size. It draws a green circle moving horizontally across a yellow background by generating frames in a loop. Each frame is converted to 8-bit indexed format and added to the GIF using the memory-efficient Pipeline API.

## Tags

- [Color Conversion](<https://www.graphicsmill.com/samples/tags/color-conversion_md>): Converting colors between color spaces
- [Drawing](<https://www.graphicsmill.com/samples/tags/drawing_md>): Drawing vector shapes and text
- [Filesystem](<https://www.graphicsmill.com/samples/tags/filesystem_md>): Loading and saving images from files
- [GIF](<https://www.graphicsmill.com/samples/tags/gif_md>): Reading, writing and animating GIFs
- [Indexed format](<https://www.graphicsmill.com/samples/tags/indexed_md>): Working with indexed-color images
- [Multiple frames](<https://www.graphicsmill.com/samples/tags/multi-frame_md>): Handling multi-frame image formats
- [Write](<https://www.graphicsmill.com/samples/tags/write_md>): Writing images with codecs

## Output

- [WriteAnimatedGif.gif](<https://www.graphicsmill.com/samples/Codecs/compiled/Debug/WriteAnimatedGif_gif>) (preview)

## Used APIs

- [Aurigma.GraphicsMill.Bitmap.ColorManagement](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Bitmap_ColorManagement.htm.md>)
- [Aurigma.GraphicsMill.Bitmap.GetGraphics](<https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_Bitmap_GetGraphics.htm.md>)
- [Aurigma.GraphicsMill.Codecs.GifFrameSettings.Delay](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Codecs_GifFrameSettings_Delay.htm.md>)
- [Aurigma.GraphicsMill.Codecs.GifWriter](<https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Codecs_GifWriter.htm.md>)
- [Aurigma.GraphicsMill.Codecs.GifWriter.FrameOptions](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Codecs_GifWriter_FrameOptions.htm.md>)
- [Aurigma.GraphicsMill.ColorManagementProvider.Convert(PixelFormat)](<https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_ColorManagementProvider_Convert_1_3e209c07.htm.md>)
- [Aurigma.GraphicsMill.Drawing.Graphics.FillEllipse(Brush,RectangleF)](<https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_Drawing_Graphics_FillEllipse_2_9763ccb2.htm.md>)
- [Aurigma.GraphicsMill.Drawing.SolidBrush](<https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Drawing_SolidBrush.htm.md>)
