Help and Support
 

powered byLive Search

GDI+ GIF files are saved using the 8-bpp format

Article ID:318343
Last Review:February 12, 2007
Revision:3.2
This article was previously published under Q318343
This article references the following .NET Framework Class Library namespaces:
System.Drawing
On This Page

SUMMARY

A GIF image file that is created by the GDI+ classes or by the System.Drawing classes is always saved using an 8 bits-per-pixel (bpp) image. This occurs because the encoder in the GIF codec that ships with GDI+ version 1.0 processes only 8-bpp Bitmaps or Images.

Back to the top

MORE INFORMATION

Although GDI+ 1.0 and the .NET Framework can work with Bitmap image objects in several different pixel formats, the GIF codec that is used with the Bitmap.Save() method can encode only the 8 bits-per-pixel format.

The GIF encoder is capable of processing both 8-bpp and 32-bpp images. When the GIF encoder receives a request to save a 32-bpp image, the GIF encloder converts the image to 8 bpp by half-toning the image. If the bitmap's pixel format is not the GIF encoder-supported 32-bpp or 8-bpp format, the Save() method converts the image to 32 bpp so that the GIF encoder can convert the image to the 8-bpp format before encoding. Thus, the GIF encoder always processes an 8-bpp format.

This may be unexpected in these ways:
The conversion that the GIF encoder uses to create an 8-bpp image from a 32-bpp image automatically sets the palette to the default halftone palette. As a result, the GIF encoder ignores any palette that may have been set for the image.
Other indexed pixel formats (for example, 1 bpp or 4 bpp) always result in a 256-color GIF file because the Bitmap.Save() method promotes the format to 32 bpp before giving the file to the GIF encoder, which then color reduces to a 256-entry color table.
When the Bitmap object's format is 8 bpp and the object is saved with the GIF codec, the codec encodes the bitmap's palette entries into the smallest GIF color table such that the color table contains all of the palette entries and does not exceed 256 (per the GIF specification).

Back to the top

GIF Files with Less Than 256 colors

To create GIF files containing less than 256 colors, use an 8-bpp Bitmap object, but reduce the size of the palette and set the pixel indexes appropriately.

To save a monochrome GIF image file, follow these steps:
1.Set the size of the Bitmap object's palette to two colors.
2.Initialize the palette with two colors, presumably black and white.
3.Create the Bitmap's definition by setting each 8-bpp color index to a byte value of zero (0) or one (1) to reference either of the palette's two colors
4.Save the bitmap using the GIF codec.
To save a 16-color GIF image file, follow these steps:
1.Set the size of the file share Bitmap object's palette to 16 entries.
2.Initialize the palette with 16 colors for entries zero (0) through 15.
3.Create the Bitmap's definition by setting each 8-bpp color index to a byte value between zero (0) and 15.
4.Save the bitmap using the GIF codec.
In each case, the GDI+ Bitmap object is an 8-bpp format image, but the Bitmap definition uses only a subset of the 8-bpp color palette (which becomes the GIF color table). The GIF codec sets the file's global color table to a size sufficiently large to contain the entries of the 8-bpp Bitmap's palette, and then the GIF codec encodes the significant bits of the image's color indexes for that color table.

Back to the top

REFERENCES

For additional information about saving a GIF with a new color table, click the article number below to view the article in the Microsoft Knowledge Base:
315780 (http://support.microsoft.com/kb/315780/EN-US/) HOWTO: Save a GIF File with a New Color Table By Using GDIplus

Back to the top

Third-party License

Microsoft has obtained a license from Unisys to use the GIF file format and other LZW technologies that are covered by the Unisys-owned U.S. and foreign patents in a number of Microsoft products. However, this license does not extend to third-party developers who use Microsoft development products or toolkits to develop applications. As a third-party developer, you need to determine whether you need to obtain a license from Unisys to use the GIF format or the LZW technologies.

For additional information about LZW licenses and GIF, click the article number below to view the article in the Microsoft Knowledge Base:
193543 (http://support.microsoft.com/kb/193543/EN-US/) INFO: Unisys GIF and LZW Technology License Information

Back to the top

GIF Defined

Graphics Interchange Format (GIF) is a stream-capable image file format that was created by CompuServe.

Back to the top


APPLIES TO
Microsoft GDI+ 1.0
Microsoft .NET Framework Software Development Kit 1.0
Microsoft Windows XP Professional

Back to the top

Keywords: 
kbinfo kbcolor kbfaq kbgdipimaging kbdswgdi2003swept KB318343

Back to the top

Article Translations

 

Related Support Centers

Other Support Options

  • Need More Help?
    Contact a Support professional by Email, Online or Phone.
  • Customer Service
    For non-technical assistance with product purchases, subscriptions, online services, events, training courses, corporate sales, piracy issues, and more.
  • Newsgroups
    Pose a question to other users. Discussion groups and Forums about specific Microsoft products, technologies, and services.