Meet us at PRINT 19. Chicago, IL. Oct. 3 - 5.
This documentation is for the old version. Go to the latest Graphics Mill docs

GIF File Format

The GIF format was designed by Compuserve in 1987. Since then it has become very popular for general image exchange. There are two types of GIF files; GIF87a, the original standard of 1987 and GIF89a, the revised standard of 1989. All of these formats are available for reading in Graphics Mill for .NET and GIF89a format is available for saving. Main advantage of GIF89a against GIF87a is animation and transparency support.

The GIF format is a lossless format and is good for saving any type of image that has 256 colors (or shades of gray), or fewer. This format is suitable as a generalized format for image exchange, however if you need to save the image with more colors, you should choose PNG, TIFF or JPEG instead of GIF. In general this is the best format for images with a limited number of colors, since the compression ratio is good (it is difficult to obtain better compression and stay lossless) and GIF files can be decompressed very quickly. GIF image format supports one-dimensional interlacing (a method of progressive display), this makes this format convenient for transmission images across slow communication links. That is why this format is very popular for Web graphics.

Format Name

GIF

MIME Type

image/gif

File Extensions

*.gif

Supported Pixel Formats

Description Read Write
1 bit palette-based Yes Yes
4 bit palette-based Yes Yes
8 bit palette-based Yes Yes

Encoder Options

Name Default Value Comments
GifEncoderOptions.BackgroundEntryIndex
GifWriter.BackgroundEntryIndex
-1 An index in the global palette for the background color.
GifFrame.ColorKeyIndex -1 Index of the transparent palette entry. If the frame has no transparent areas, -1 is returned.
GifEncoderOptions.Delay
GifFrame.Delay
0

Number of hundredths (1/100) of a second to wait after rendering the frame.

GifEncoderOptions.DisposalMethod
GifFrame.DisposalMethod
DisposalMethod.None Codecs.DisposalMethod value that specifies a disposal method for the frame.
GifEncoderOptions.GlobalPalette
GifWriter.GlobalPalette
N/A

GraphicsMill.ColorPalette class instance that specifies a global palette for the animated GIF.

GifEncoderOptions.Height
GifWriter.Height
0 Entire GIF file height (in pixels).
GifEncoderOptions.Interlaced
GifFrame.Interlaced
false Value that specifies if the frame should be interlaced.
GifEncoderOptions.LocalPaletteEnabled
GifFrame.LocalPaletteEnabled
true

Value that specify if local palette of the frames should be saved.

GifEncoderOptions.PlaybackCount
GifWriter.PlaybackCount
0 A number of times to play the GIF file. If this property is 0, the file is played infinitely.
GifEncoderOptions.Width
GifWriter.Width
0 Entire GIF file width (in pixels).

Examples

The following examples show how to work with simple GIF files. If you need to proccess animated files, see the Loading and Saving Animated GIFs topic.

Loading Simple GIF Files

Simple GIF files are the plain images without an animation. The simplest way to load such GIF file is to pass its name to the constructor:

Visual Basic
Dim bitmap As New Aurigma.GraphicsMill.Bitmap("c:\Mountain.gif")
C#
Aurigma.GraphicsMill.Bitmap bitmap = new Aurigma.GraphicsMill.Bitmap(@"c:\Mountain.gif");

Alternatively, if you already have an instance of the Bitmap, you can use Load method:

Visual Basic
Dim bitmap As New Aurigma.GraphicsMill.Bitmap
bitmap.Load("c:\Mountain.gif")
C#
Aurigma.GraphicsMill.Bitmap bitmap = new Aurigma.GraphicsMill.Bitmap();
bitmap.Load(@"c:\Mountain.gif");        

Saving Simple GIF Files

Let's assume that we want to load a JPEG file and save this image as a web-optimized GIF file (for example, reduce number of colors to 32). This code example demonstrates how to do it:

Visual Basic
Dim bitmap As New Aurigma.GraphicsMill.Bitmap("c:\Mountain.jpg")

bitmap.ColorManagement.PaletteEntryCount = 32
bitmap.ColorManagement.ConvertToIndexed(8, Aurigma.GraphicsMill.ColorPaletteType.Adaptive, _
    Nothing)

bitmap.Save("C:\Mountain.gif", _
    New Aurigma.GraphicsMill.Codecs.GifEncoderOptions)

bitmap.Dispose()
C#
using (Aurigma.GraphicsMill.Bitmap bitmap = 
           new Aurigma.GraphicsMill.Bitmap(@"c:\Mountain.jpg"))
{
    bitmap.ColorManagement.PaletteEntryCount = 32;
    bitmap.ColorManagement.ConvertToIndexed(8, Aurigma.GraphicsMill.ColorPaletteType.Adaptive, 
        null);

    bitmap.Save(@"C:\Mountain.gif", 
        new Aurigma.GraphicsMill.Codecs.GifEncoderOptions());
}

See Also

Manual