GDI+ GIF files are saved using the 8-bpp format (318343)
The information in this article applies to:
- Microsoft GDI+ 1.0
- Microsoft .NET Framework SDK
- Microsoft Windows XP Professional
- the operating system: Microsoft Windows XP 64-Bit Edition
This article was previously published under Q318343 This article references the following .NET Framework Class
Library namespaces:
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. 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). 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:
- Set the size of the Bitmap object's palette to two colors.
- Initialize the palette with two colors, presumably black
and white.
- 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
- Save the bitmap using the GIF codec.
To save a 16-color GIF image file, follow these steps:
- Set the size of the file share Bitmap object's palette to 16 entries.
- Initialize the palette with 16 colors for entries zero (0)
through 15.
- Create the Bitmap's definition by setting each 8-bpp color index to a byte value
between zero (0) and 15.
- 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. REFERENCESFor
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 HOWTO: Save a GIF File with a New Color Table By Using GDIplus
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 INFO: Unisys GIF and LZW Technology License Information
GIF Defined Graphics Interchange Format (GIF) is a stream-capable image file
format that was created by CompuServe.
Modification Type: | Minor | Last Reviewed: | 5/3/2006 |
---|
Keywords: | kbDSWGDI2003Swept kbColor kbgdipimaging kbinfo KB318343 |
---|
|