GifEncoder Class |
An ImageEncoder that will write Compuserve Graphics Interchange (GIF) images to a Stream.
Namespace: Atalasoft.Imaging.Codec
The GifEncoder type exposes the following members.
Name | Description | |
---|---|---|
GifEncoder | Initializes a new instance of a %GifEncoder%. | |
GifEncoder(Boolean) | Initializes a new instance of a %BmpEncoder% specifying the interlace setting. | |
GifEncoder(Boolean, Boolean) | Creates a new instance of GifEncoder specifying whether to interlace the image and optimize color depth.
|
Name | Description | |
---|---|---|
BackgroundIndex | Gets or sets the background index to store in the GIF file. | |
Interlace | Gets or sets a value indicating if the image is saved with a pixel row interlacing pattern. Default
false | |
OptimizeColorDepth | Gets or sets a value indicating if the bitdepth is optimized based on the number of colors in the palette.
Default true. | |
SupportedPixelFormats | Returns an array of pixel formats supported by this encoder. (Overrides ImageEncoderSupportedPixelFormats.) |
Name | Description | |
---|---|---|
Equals | Determines whether the specified object is equal to the current object. (Inherited from Object.) | |
Finalize | Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.) | |
GetHashCode | Serves as the default hash function. (Inherited from Object.) | |
GetType | Gets the Type of the current instance. (Inherited from Object.) | |
IsPixelFormatSupported | Returns true if the given PixelFormat can be encoded with the derived encoder. (Inherited from ImageEncoder.) | |
MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object.) | |
Save(Stream, AtalaImage, ProgressEventHandler) | Encode an AtalaImage as a Gif image to a stream. (Overrides ImageEncoderSave(Stream, AtalaImage, ProgressEventHandler).) | |
Save(Stream, GifFrameCollection, ProgressEventHandler) | Saves an animated GIF image. | |
ToString | Returns a string that represents the current object. (Inherited from Object.) |
This ImageEncoder can be passed into the the AtalaImage or Workspace objects when saving to specify a GIF image.
Gif Images typicaly have one color which is transparent. When saving with a GifFrameCollection object, this is indicated by the TransparentIndex property of each GifFrame.
When saving with a regular AtalaImage or ImageCollection, the transparent index is determined automaticaly. Each color in the palette can have an alpha value between 0 and 255. The GifEncoder will chose (as the transparent color) the first fully transparent color in the palette, that is the first color with an alpha value of 255.
private void CreateAnimatedGif(string fileName, ImageCollection images) { // Find the maximum size of the animation. int width = 0; int height = 0; foreach(AtalaImage img in images) { if (img.Width > width) width = img.Width; if (img.Height > height) height = img.Height; } // Create the frame collection. GifFrameCollection col = new GifFrameCollection(); col.Width = width; col.Height = height; col.LoopCount = 0; // infinite col.TransparentIndex = -1; // no transparency // Center each image. foreach(AtalaImage img in images) { GifFrame frame = new GifFrame(img, new Point((width - img.Width) / 2, (height - img.Height) / 2)); col.Add(frame); } // Save the image. FileStream fs = new FileStream(fileName, FileMode.Create, FileAccess.Write); GifEncoder encoder = new GifEncoder(); encoder.Save(fs, col, null); fs.Close(); // Free the collection. col.Dispose(); }
Private Sub CreateAnimatedGif(ByVal fileName As String, ByVal images As ImageCollection) ' Find the maximum size of the animation. Dim width As Integer = 0 Dim height As Integer = 0 Dim img As AtalaImage For Each img In images If img.Width > width Then width = img.Width End If If img.Height > height Then height = img.Height End If Next ' Create the frame collection. Dim col As GifFrameCollection = New GifFrameCollection() col.Width = width col.Height = height col.LoopCount = 0 ' infinite col.TransparentIndex = -1 ' no transparency ' Center each image. Dim img As AtalaImage For Each img In images Dim frame As GifFrame = New GifFrame(img, New Point((width - img.Width) / 2,(height - img.Height) / 2)) col.Add(frame) Next ' Save the image. Dim fs As FileStream = New FileStream(fileName,FileMode.Create,FileAccess.Write) Dim encoder As GifEncoder = New GifEncoder() encoder.Save(fs, col, Nothing) fs.Close() ' Free the collection. col.Dispose() End Sub