---
title: "Resize Animated Gif"
canonical: https://www.graphicsmill.com/samples/Codecs/Gif/ResizeAnimatedGif_cs
product: "Graphics Mill"
source: "Codecs/Gif/ResizeAnimatedGif.cs"
---

# Resize Animated Gif

Resizes animated image in GIF format.

## Instruction

Resize an animated GIF image to a fixed width and height while preserving animation properties such as palette, playback count, and frame settings. Use the memory-friendly Pipeline API where applicable.

## Usings

```csharp
using System;
using Aurigma.GraphicsMill.Codecs;
using Aurigma.GraphicsMill.Transforms;
```

## Code Snippet

```csharp
const int width = 400;
const int height = 400;

using (var reader = new GifReader("AnimatedGif.gif"))
{
    var kX = (float)width / (float)reader.Width;
    var kY = (float)height / (float)reader.Height;

    using (var writer = new GifWriter("ResizeAnimatedGif.gif"))
    {
        // Copy general properties of the source file
        writer.BackgroundIndex = reader.BackgroundEntryIndex;
        writer.Palette = reader.Palette;
        writer.PlaybackCount = reader.PlaybackCount;

        for (int i = 0; i < reader.Frames.Count; i++)
        {
            // Read a frame
            using (var frame = (GifFrame)reader.Frames[i])
            using (var bitmap = frame.GetBitmap())
            {
                // Preserve the original palette
                ColorPalette palette = bitmap.Palette;

                // Preserve the original pixel format
                PixelFormat pixelFormat = bitmap.PixelFormat;

                // Convert the bitmap to a non-indexed format
                bitmap.ColorManagement.Convert(Aurigma.GraphicsMill.ColorSpace.Rgb, true, false);

                // Resize the bitmap in a low quality mode to prevent noise
                var newWidth = Math.Max(1, (int)((float)bitmap.Width * kX));
                var newHeight = Math.Max(1, (int)((float)bitmap.Height * kY));
                bitmap.Transforms.Resize(newWidth, newHeight, ResizeInterpolationMode.Low);

                // Return to the indexed format
                bitmap.ColorManagement.Palette = palette;
                bitmap.ColorManagement.Convert(pixelFormat);

                // Copy frame settings
                writer.FrameOptions.Left = (ushort)((float)frame.Left * kX);
                writer.FrameOptions.Top = (ushort)((float)frame.Top * kY);
                writer.FrameOptions.Delay = frame.Delay;
                writer.FrameOptions.DisposalMethod = frame.DisposalMethod;

                // Add the frame
                Pipeline.Run(bitmap + writer);
            }
        }
    }
}
```

## Explanation

Here is a C# program that loads an animated GIF, resizes each frame to 400x400, and saves the result as a new animated GIF using the Pipeline API:

This code reads `AnimatedGif.gif`, resizes each frame while preserving palette and frame-specific metadata, and writes them to `ResizeAnimatedGif.gif`. It uses the Pipeline API for memory-efficient frame writing.

## Tags

- [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
- [Multiple frames](<https://www.graphicsmill.com/samples/tags/multi-frame_md>): Handling multi-frame image formats
- [Read](<https://www.graphicsmill.com/samples/tags/read_md>): Reading images with codecs
- [Resize](<https://www.graphicsmill.com/samples/tags/resize_md>): Resizing images
- [Write](<https://www.graphicsmill.com/samples/tags/write_md>): Writing images with codecs

## Input

- [AnimatedGIF.gif](<https://www.graphicsmill.com/samples/Codecs/compiled/Debug/AnimatedGIF_gif>) (preview)

## Output

- [ResizeAnimatedGif.gif](<https://www.graphicsmill.com/samples/Codecs/compiled/Debug/ResizeAnimatedGif_gif>) (preview)

## Used APIs

- [Aurigma.GraphicsMill.Bitmap.ColorManagement](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Bitmap_ColorManagement.htm.md>)
- [Aurigma.GraphicsMill.Bitmap.Palette](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Bitmap_Palette.htm.md>)
- [Aurigma.GraphicsMill.Bitmap.PixelFormat](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Bitmap_PixelFormat.htm.md>)
- [Aurigma.GraphicsMill.Bitmap.Transforms](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Bitmap_Transforms.htm.md>)
- [Aurigma.GraphicsMill.Codecs.Frame.GetBitmap](<https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_Codecs_Frame_GetBitmap.htm.md>)
- [Aurigma.GraphicsMill.Codecs.FrameCollectionBase.Count](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Codecs_FrameCollectionBase_Count.htm.md>)
- [Aurigma.GraphicsMill.Codecs.GifFrame](<https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Codecs_GifFrame.htm.md>)
- [Aurigma.GraphicsMill.Codecs.GifFrame.Delay](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Codecs_GifFrame_Delay.htm.md>)
- [Aurigma.GraphicsMill.Codecs.GifFrame.DisposalMethod](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Codecs_GifFrame_DisposalMethod.htm.md>)
- [Aurigma.GraphicsMill.Codecs.GifFrame.Left](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Codecs_GifFrame_Left.htm.md>)
- [Aurigma.GraphicsMill.Codecs.GifFrame.Top](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Codecs_GifFrame_Top.htm.md>)
- [Aurigma.GraphicsMill.Codecs.GifFrameSettings.Delay](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Codecs_GifFrameSettings_Delay.htm.md>)
- [Aurigma.GraphicsMill.Codecs.GifFrameSettings.DisposalMethod](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Codecs_GifFrameSettings_DisposalMethod.htm.md>)
- [Aurigma.GraphicsMill.Codecs.GifFrameSettings.Left](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Codecs_GifFrameSettings_Left.htm.md>)
- [Aurigma.GraphicsMill.Codecs.GifFrameSettings.Top](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Codecs_GifFrameSettings_Top.htm.md>)
- [Aurigma.GraphicsMill.Codecs.GifReader](<https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Codecs_GifReader.htm.md>)
- [Aurigma.GraphicsMill.Codecs.GifReader.BackgroundEntryIndex](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Codecs_GifReader_BackgroundEntryIndex.htm.md>)
- [Aurigma.GraphicsMill.Codecs.GifReader.Frames](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Codecs_GifReader_Frames.htm.md>)
- [Aurigma.GraphicsMill.Codecs.GifReader.PlaybackCount](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Codecs_GifReader_PlaybackCount.htm.md>)
- [Aurigma.GraphicsMill.Codecs.GifWriter](<https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Codecs_GifWriter.htm.md>)
- [Aurigma.GraphicsMill.Codecs.GifWriter.BackgroundIndex](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Codecs_GifWriter_BackgroundIndex.htm.md>)
- [Aurigma.GraphicsMill.Codecs.GifWriter.FrameOptions](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Codecs_GifWriter_FrameOptions.htm.md>)
- [Aurigma.GraphicsMill.Codecs.GifWriter.Palette](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Codecs_GifWriter_Palette.htm.md>)
- [Aurigma.GraphicsMill.Codecs.GifWriter.PlaybackCount](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Codecs_GifWriter_PlaybackCount.htm.md>)
- [Aurigma.GraphicsMill.Codecs.ImageReader.Palette](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Codecs_ImageReader_Palette.htm.md>)
- [Aurigma.GraphicsMill.ColorManagementProvider.Convert(ColorSpace,Boolean,Boolean)](<https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_ColorManagementProvider_Convert_3_5d5173a9.htm.md>)
- [Aurigma.GraphicsMill.ColorManagementProvider.Convert(PixelFormat)](<https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_ColorManagementProvider_Convert_1_3e209c07.htm.md>)
- [Aurigma.GraphicsMill.ColorManagementProvider.Palette](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_ColorManagementProvider_Palette.htm.md>)
- [Aurigma.GraphicsMill.ColorPalette](<https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_ColorPalette.htm.md>)
- [Aurigma.GraphicsMill.ColorSpace](<https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_ColorSpace.htm.md>)
- [Aurigma.GraphicsMill.Transforms.ResizeInterpolationMode](<https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Transforms_ResizeInterpolationMode.htm.md>)
- [Aurigma.GraphicsMill.TransformsProvider.Resize(Int32,Int32,ResizeInterpolationMode)](<https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_TransformsProvider_Resize_3_db5aa34c.htm.md>)
