GifBitmapEncoder Class
Defines an encoder that is used to encode Graphics Interchange Format (GIF) images.
Assembly: PresentationCore (in PresentationCore.dll)
XMLNS for XAML: http://schemas.microsoft.com/winfx/2006/xaml/presentation, http://schemas.microsoft.com/netfx/2007/xaml/presentation
Graphics Interchange Format (GIF) images do not support global preview, global thumbnails, global metadata, frame level thumbnails, or frame level metadata. Graphics Interchange Format (GIF) images do support multiple frames.
Encoding does not work in partial trust. See Windows Presentation Foundation Partial Trust Security for information on partial trust.
The following examples show how to decode and encode a Graphics Interchange Format (GIF) image using the specific GifBitmapDecoder and GifBitmapEncoder objects. For the complete sample, see GIF Encoder and Decoder Sample
This example demonstrates how to decode a GIF image using a GifBitmapDecoder from a FileStream.
// Open a Stream and decode a GIF image Stream imageStreamSource = new FileStream("tulipfarm.gif", FileMode.Open, FileAccess.Read, FileShare.Read); GifBitmapDecoder decoder = new GifBitmapDecoder(imageStreamSource, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default); BitmapSource bitmapSource = decoder.Frames[0]; // Draw the Image Image myImage = new Image(); myImage.Source = bitmapSource; myImage.Stretch = Stretch.None; myImage.Margin = new Thickness(20);
This example demonstrates how to encode a BitmapSource into a GIF image using a GifBitmapEncoder.
int width = 128; int height = width; int stride = width / 8; byte[] pixels = new byte[height * stride]; // Define the image palette BitmapPalette myPalette = BitmapPalettes.WebPalette; // Creates a new empty image with the pre-defined palette BitmapSource image = BitmapSource.Create( width, height, 96, 96, PixelFormats.Indexed1, myPalette, pixels, stride); FileStream stream = new FileStream("new.gif", FileMode.Create); GifBitmapEncoder encoder = new GifBitmapEncoder(); TextBlock myTextBlock = new TextBlock(); myTextBlock.Text = "Codec Author is: " + encoder.CodecInfo.Author.ToString(); encoder.Frames.Add(BitmapFrame.Create(image)); encoder.Save(stream);
System.Windows.Threading.DispatcherObject
System.Windows.Media.Imaging.BitmapEncoder
System.Windows.Media.Imaging.GifBitmapEncoder
Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.