GifImage Class
A gif image.
Inheritance Hierarchy

Namespace: Aspose.Imaging.FileFormats.Gif
Assembly: Aspose.Imaging (in Aspose.Imaging.dll) Version: 21.05
Syntax
public sealed class GifImage : RasterCachedMultipageImage, 
	IMultipageImage, IMultipageImageExt

The GifImage type exposes the following members.

Constructors
  NameDescription
Public methodCode exampleGifImage(GifFrameBlock)
Initializes a new instance of the GifImage class.
Public methodCode exampleGifImage(GifFrameBlock, IColorPalette)
Initializes a new instance of the GifImage class.
Public methodGifImage(GifFrameBlock, IColorPalette, Boolean, Byte, Byte, Byte, Boolean)
Initializes a new instance of the GifImage class.
Properties
  NameDescription
Public propertyCode exampleActiveFrame
Gets or sets the active frame.
Public propertyAutoAdjustPalette
Gets or sets a value indicating whether automatic adjust palette.
(Inherited from Image.)
Public propertyBackgroundColor
Gets or sets the background color.
(Overrides RasterCachedMultipageImageBackgroundColor.)
Public propertyBackgroundColorIndex
Gets or sets the background color index.
Public propertyBitsPerPixel
Gets the image bits per pixel count.
(Inherited from RasterCachedMultipageImage.)
Public propertyBlocks
Gets the GIF blocks.
Public propertyBounds
Gets the image bounds.
(Inherited from Image.)
Public propertyBufferSizeHint
Gets or sets the buffer size hint which is defined max allowed size for all internal buffers.
(Inherited from Image.)
Public propertyContainer
Gets the Image container.
(Inherited from Image.)
Public propertyDataStreamContainer
Gets the object's data stream.
(Inherited from DataStreamSupporter.)
Public propertyDefaultPage Obsolete.
Gets the default page.
(Overrides RasterCachedMultipageImageDefaultPage.)
Public propertyDisposed
Gets a value indicating whether this instance is disposed.
(Inherited from DisposableObject.)
Public propertyFileFormat
Gets a value of file format
(Overrides ImageFileFormat.)
Public propertyHasAlpha
Gets a value indicating whether this instance has alpha.
(Inherited from RasterCachedMultipageImage.)
Public propertyHasBackgroundColor
Gets a value indicating whether image has background color.
(Overrides ImageHasBackgroundColor.)
Public propertyHasTrailer
Gets or sets a value indicating whether GIF has trailer.
Public propertyHasTransparentColor
Gets a value indicating whether active frame has transparent color.
(Overrides RasterCachedMultipageImageHasTransparentColor.)
Public propertyHeight
Gets the image height.
(Inherited from RasterCachedMultipageImage.)
Public propertyCode exampleHorizontalResolution
Gets or sets the horizontal resolution, in pixels per inch, of this RasterImage.
(Inherited from RasterImage.)
Public propertyImageOpacity
Gets opacity of this image (active frame).
(Overrides RasterCachedMultipageImageImageOpacity.)
Public propertyInterruptMonitor
Gets or sets the interrupt monitor.
(Inherited from Image.)
Public propertyIsCached
Gets a value indicating whether image data is cached currently.
(Inherited from RasterCachedMultipageImage.)
Public propertyIsInterlaced
Gets a value indicating whether this image instance is interlaced.
Public propertyIsPaletteSorted
Gets or sets a value indicating whether palette is sorted.
Public propertyIsRawDataAvailable
Gets a value indicating whether raw data loading is available.
(Inherited from RasterImage.)
Public propertyPageCount
Gets the page count.
(Overrides RasterCachedMultipageImagePageCount.)
Public propertyPageExportingAction
Gets or sets the page exporting action. Please note that setting this method will automatically release page resources after it is executed. It will be executed just before each page is saved.
(Overrides RasterCachedMultipageImagePageExportingAction.)
Public propertyPages
Gets the pages.
(Overrides RasterCachedMultipageImagePages.)
Public propertyPalette
Gets or sets the color palette. The color palette is not used when pixels are represented directly.
(Inherited from Image.)
Public propertyPaletteColorResolutionBits
Gets or sets the palette color resolution bits.
Public propertyPixelAspectRatio
Gets or sets the pixel aspect ratio.
Public propertyCode examplePremultiplyComponents
Gets or sets a value indicating whether the image components must be premultiplied.
(Inherited from RasterImage.)
Public propertyRawCustomColorConverter
Gets or sets the custom color converter
(Inherited from RasterImage.)
Public propertyCode exampleRawDataFormat
Gets the raw data format.
(Inherited from RasterImage.)
Public propertyRawDataSettings
Gets the current raw data settings. Note when using these settings the data loads without conversion.
(Inherited from RasterImage.)
Public propertyRawFallbackIndex
Gets or sets the fallback index to use when palette index is out of bounds
(Inherited from RasterImage.)
Public propertyRawIndexedColorConverter
Gets or sets the indexed color converter
(Inherited from RasterImage.)
Public propertyRawLineSize
Gets the raw line size in bytes.
(Inherited from RasterImage.)
Public propertyCode exampleSize
Gets the image size.
(Inherited from Image.)
Public propertyTransparentColor
Gets active frame transparent color.
(Overrides RasterImageTransparentColor.)
Public propertyUpdateXmpData
Gets or sets a value indicating whether to update the XMP metadata.
(Inherited from RasterImage.)
Public propertyUsePalette
Gets a value indicating whether the image palette is used.
(Inherited from RasterImage.)
Public propertyUseRawData
Gets or sets a value indicating whether to use raw data loading when the raw data loading is available.
(Inherited from RasterImage.)
Public propertyCode exampleVerticalResolution
Gets or sets the vertical resolution, in pixels per inch, of this RasterImage.
(Inherited from RasterImage.)
Public propertyWidth
Gets the image width.
(Inherited from RasterCachedMultipageImage.)
Public propertyXmpData
Gets or sets the XMP metadata.
(Overrides RasterCachedMultipageImageXmpData.)
Methods
  NameDescription
Public methodCode exampleAddBlock
Adds a new GIF block.
Public methodCode exampleAddPage
Adds page to the image.
Public methodCode exampleAdjustBrightness
Adjust of a brightness for image.
(Overrides RasterCachedMultipageImageAdjustBrightness(Int32).)
Public methodCode exampleAdjustContrast
Adjusts the contrast.
(Overrides RasterCachedMultipageImageAdjustContrast(Single).)
Public methodCode exampleAdjustGamma(Single)
Gamma-correction of an image.
(Overrides RasterCachedMultipageImageAdjustGamma(Single).)
Public methodCode exampleAdjustGamma(Single, Single, Single)
Gamma-correction of an image.
(Overrides RasterCachedMultipageImageAdjustGamma(Single, Single, Single).)
Public methodBinarizeBradley(Double)
Binarization of an image using Bradley's adaptive thresholding algorithm using the integral image thresholding
(Overrides RasterCachedMultipageImageBinarizeBradley(Double).)
Public methodBinarizeBradley(Double, Int32)
Binarization of an image using Bradley's adaptive thresholding algorithm using the integral image thresholding
(Inherited from RasterCachedMultipageImage.)
Public methodCode exampleBinarizeFixed
Binarization of an image with predefined threshold
(Overrides RasterCachedMultipageImageBinarizeFixed(Byte).)
Public methodCode exampleBinarizeOtsu
Binarization of an image with Otsu thresholding
(Overrides RasterCachedMultipageImageBinarizeOtsu.)
Public methodCacheData
Caches the data private.
(Inherited from RasterCachedMultipageImage.)
Public methodCode exampleCanSave
Determines whether image can be saved to the specified file format represented by the passed save options.
(Inherited from Image.)
Public methodCode exampleClearBlocks
Clears all the GIF blocks.
Public methodCode exampleCrop(Rectangle)
Cropping the image.
(Overrides RasterCachedMultipageImageCrop(Rectangle).)
Public methodCrop(Int32, Int32, Int32, Int32)
Crop image with shifts.
(Inherited from RasterCachedMultipageImage.)
Public methodCode exampleDispose
Disposes the current instance.
(Inherited from DisposableObject.)
Public methodCode exampleDither(DitheringMethod, Int32)
Performs dithering on the current image.
(Inherited from RasterImage.)
Public methodCode exampleDither(DitheringMethod, Int32, IColorPalette)
Performs dithering on the current image.
(Overrides RasterCachedMultipageImageDither(DitheringMethod, Int32, IColorPalette).)
Public methodEquals
Determines whether the specified Object is equal to the current Object.
(Inherited from Object.)
Public methodCode exampleFilter
Filters the specified rectangle.
(Overrides RasterCachedMultipageImageFilter(Rectangle, FilterOptionsBase).)
Public methodCode exampleGetArgb32Pixel
Gets an image 32-bit ARGB pixel.
(Inherited from RasterImage.)
Public methodGetDefaultArgb32Pixels
Gets the default 32-bit ARGB pixels array.
(Inherited from RasterImage.)
Public methodGetDefaultOptions
Gets the default options.
(Inherited from Image.)
Public methodGetDefaultPixels
Gets the default pixels array using partial pixel loader.
(Inherited from RasterImage.)
Public methodGetDefaultRawData(Rectangle, RawDataSettings)
Gets the default raw data array.
(Inherited from RasterImage.)
Public methodGetDefaultRawData(Rectangle, IPartialRawDataLoader, RawDataSettings)
Gets the default raw data array using partial pixel loader.
(Inherited from RasterImage.)
Public methodGetHashCode
Serves as a hash function for a particular type.
(Inherited from Object.)
Public methodGetModifyDate
Gets the date and time the resource image was last modified.
(Inherited from RasterImage.)
Public methodGetOriginalOptions
Gets the options based on the original file settings. This can be helpful to keep bit-depth and other parameters of the original image unchanged. For example, if we load a black-white PNG image with 1 bit per pixel and then save it using the Save(String) method, the output PNG image with 8-bit per pixel will be produced. To avoid it and save PNG image with 1-bit per pixel, use this method to get corresponding saving options and pass them to the Save(String, ImageOptionsBase) method as the second parameter.
(Inherited from Image.)
Public methodCode exampleGetPixel
Gets an image pixel.
(Inherited from RasterImage.)
Public methodGetSkewAngle
Gets the skew angle. This method is applicable to scanned text documents, to determine the skew angle when scanning.
(Inherited from RasterImage.)
Public methodGetType
Gets the type of the current instance.
(Inherited from Object.)
Public methodCode exampleGrayscale
Transformation of an image to its grayscale representation
(Overrides RasterCachedMultipageImageGrayscale.)
Public methodInsertBlock
Adds a new GIF block.
Public methodCode exampleLoadArgb32Pixels
Loads 32-bit ARGB pixels.
(Inherited from RasterImage.)
Public methodCode exampleLoadArgb64Pixels
Loads 64-bit ARGB pixels.
(Inherited from RasterImage.)
Public methodLoadCmyk32Pixels
Loads pixels in CMYK format.
(Inherited from RasterImage.)
Public methodLoadCmykPixels Obsolete.
Loads pixels in CMYK format. This method is deprecated. Please use more effective the LoadCmyk32Pixels(Rectangle) method.
(Inherited from RasterImage.)
Public methodCode exampleLoadPartialArgb32Pixels
Loads 32-bit ARGB pixels partially by packs.
(Inherited from RasterImage.)
Public methodCode exampleLoadPartialPixels
Loads pixels partially by packs.
(Inherited from RasterImage.)
Public methodCode exampleLoadPixels
Loads pixels.
(Inherited from RasterImage.)
Public methodCode exampleLoadRawData(Rectangle, RawDataSettings, IPartialRawDataLoader)
Loads raw data.
(Inherited from RasterImage.)
Public methodLoadRawData(Rectangle, Rectangle, RawDataSettings, IPartialRawDataLoader)
Loads raw data.
(Inherited from RasterImage.)
Public methodNormalizeAngle
Normalizes the angle. This method is applicable to scanned text documents to get rid of the skewed scan. This method uses GetSkewAngle and Rotate(Single) methods.
(Inherited from RasterImage.)
Public methodNormalizeAngle(Boolean, Color)
Normalizes the angle. This method is applicable to scanned text documents to get rid of the skewed scan. This method uses [!:GetSkewAngle] and Rotate(Single, Boolean, Color) methods.
(Inherited from RasterCachedMultipageImage.)
Public methodOrderBlocks
Orders the GIF blocks according to the GIF specification. Some GifGraphicsControlBlock may be removed for proper GIF layout.
Public methodReadArgb32ScanLine
Reads the whole scan line by the specified scan line index.
(Inherited from RasterImage.)
Public methodReadScanLine
Reads the whole scan line by the specified scan line index.
(Inherited from RasterImage.)
Public methodRemoveBlock
Removes the GIF block.
Public methodReplaceColor(Int32, Byte, Int32)
Replaces one color to another with allowed difference and preserves original alpha value to save smooth edges.
(Inherited from RasterCachedMultipageImage.)
Public methodReplaceColor(Color, Byte, Color)
Replaces one color to another with allowed difference and preserves original alpha value to save smooth edges.
(Inherited from RasterImage.)
Public methodReplaceNonTransparentColors(Int32)
Replaces all non-transparent colors with new color and preserves original alpha value to save smooth edges. Note: if you use it on images without transparency, all colors will be replaced with a single one.
(Inherited from RasterCachedMultipageImage.)
Public methodReplaceNonTransparentColors(Color)
Replaces all non-transparent colors with new color and preserves original alpha value to save smooth edges. Note: if you use it on images without transparency, all colors will be replaced with a single one.
(Inherited from RasterImage.)
Public methodCode exampleResize(Int32, Int32)
Resizes the image. The default LeftTopToLeftTop is used.
(Inherited from Image.)
Public methodCode exampleResize(Int32, Int32, ImageResizeSettings)
Resizes the image.
(Overrides RasterCachedMultipageImageResize(Int32, Int32, ImageResizeSettings).)
Public methodCode exampleResize(Int32, Int32, ResizeType)
Resizes the image.
(Overrides RasterCachedMultipageImageResize(Int32, Int32, ResizeType).)
Public methodResizeHeightProportionally(Int32)
Resizes the height proportionally.
(Inherited from Image.)
Public methodResizeHeightProportionally(Int32, ImageResizeSettings)
Resizes the height proportionally.
(Inherited from Image.)
Public methodResizeHeightProportionally(Int32, ResizeType)
Resizes the width proportionally.
(Inherited from RasterCachedMultipageImage.)
Public methodResizeProportional
Performs proportional resize on the image. The proportional resize will resize each frame according to the ratio of newWidth/width and newHeight/height.
Public methodResizeWidthProportionally(Int32)
Resizes the width proportionally.
(Inherited from Image.)
Public methodResizeWidthProportionally(Int32, ImageResizeSettings)
Resizes the width proportionally.
(Inherited from Image.)
Public methodResizeWidthProportionally(Int32, ResizeType)
Resizes the width proportionally.
(Inherited from RasterCachedMultipageImage.)
Public methodRotate(Single)
Rotate image around the center.
(Inherited from RasterImage.)
Public methodRotate(Single, Boolean, Color)
[!:RasterCahcedMultipageImage.Rotate] image around the center.
(Overrides RasterCachedMultipageImageRotate(Single, Boolean, Color).)
Public methodCode exampleRotateFlip
Rotates, flips, or rotates and flips the Active frame only.
(Overrides RasterCachedMultipageImageRotateFlip(RotateFlipType).)
Public methodRotateFlipAll Obsolete.
Rotates the flip all.
(Inherited from RasterCachedMultipageImage.)
Public methodCode exampleSave
Saves the image data to the underlying stream.
(Inherited from Image.)
Public methodSave(Stream)
Saves the object's data to the specified stream.
(Inherited from DataStreamSupporter.)
Public methodSave(String)
Saves the object's data to the specified file location.
(Inherited from DataStreamSupporter.)
Public methodSave(String, Boolean)
Saves the object's data to the specified file location.
(Inherited from DataStreamSupporter.)
Public methodCode exampleSave(Stream, ImageOptionsBase)
Saves the image's data to the specified stream in the specified file format according to save options.
(Inherited from Image.)
Public methodCode exampleSave(String, ImageOptionsBase)
Saves the object's data to the specified file location in the specified file format according to save options.
(Inherited from Image.)
Public methodCode exampleSave(String, ImageOptionsBase, Rectangle)
Saves the object's data to the specified file location in the specified file format according to save options.
(Inherited from Image.)
Public methodSave(Stream, ImageOptionsBase, Rectangle)
Saves the image's data to the specified stream in the specified file format according to save options.
(Inherited from RasterImage.)
Public methodCode exampleSaveArgb32Pixels
Saves the 32-bit ARGB pixels.
(Inherited from RasterImage.)
Public methodCode exampleSaveCmyk32Pixels
Saves the pixels.
(Inherited from RasterImage.)
Public methodSaveCmykPixels Obsolete. (Inherited from RasterImage.)
Public methodCode exampleSavePixels
Saves the pixels.
(Inherited from RasterImage.)
Public methodSaveRawData
Saves the raw data.
(Inherited from RasterImage.)
Public methodCode exampleSetArgb32Pixel
Sets an image 32-bit ARGB pixel for the specified position.
(Inherited from RasterImage.)
Public methodSetPalette
Sets the image palette.
(Inherited from RasterImage.)
Public methodCode exampleSetPixel
Sets an image pixel for the specified position.
(Inherited from RasterImage.)
Public methodCode exampleSetResolution
Sets the resolution for this RasterImage.
(Inherited from RasterImage.)
Public methodToBitmap
Converts raster image to the bitmap.
(Inherited from RasterImage.)
Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)
Public methodWriteArgb32ScanLine
Writes the whole scan line to the specified scan line index.
(Inherited from RasterImage.)
Public methodWriteScanLine
Writes the whole scan line to the specified scan line index.
(Inherited from RasterImage.)
Examples
Export of part of animation from GIF image based on time interval.
[C#]

using (var image = Image.Load("Animation.gif"))
{
    var options = new GifOptions
    {
        FullFrame = true,
        MultiPageOptions = new MultiPageOptions
        {
            Mode = MultiPageMode.TimeInterval,
            TimeInterval = new TimeInterval(0, 400)
        }
    };

    image.Save("PartOfAnimation.gif", options);
}
Examples
This example shows how to create a GIF image and save it to a file.
[C#]

string dir = "c:\\temp\\";

// Create a GIF Frame block of 100x100 px.
using (Aspose.Imaging.FileFormats.Gif.Blocks.GifFrameBlock firstBlock = new Aspose.Imaging.FileFormats.Gif.Blocks.GifFrameBlock(100, 100))
{
    // Fill the entire block in red.
    Aspose.Imaging.Graphics gr = new Aspose.Imaging.Graphics(firstBlock);
    Aspose.Imaging.Brushes.SolidBrush brush = new Aspose.Imaging.Brushes.SolidBrush(Aspose.Imaging.Color.Red);
    gr.FillRectangle(brush, firstBlock.Bounds);

    using (Aspose.Imaging.FileFormats.Gif.GifImage gifImage = new Aspose.Imaging.FileFormats.Gif.GifImage(firstBlock))
    {
        gifImage.Save(dir + "output.gif");
    }
}
Examples
Create multipage GIF image using single page raster images.
[C#]

static void Main(string[] args)
{
    // Load frames
    var frames = LoadFrames("Animation frames").ToArray();

    // Create GIF image using the first frame
    using (var image = new GifImage(new GifFrameBlock(frames[0])))
    {
        // Add frames to the GIF image using the AddPage method
        for (var index = 1; index < frames.Length; index++)
        {
            image.AddPage(frames[index]);
        }

        // Save GIF image
        image.Save("Multipage.gif");
    }
}

private static IEnumerable<RasterImage> LoadFrames(string directory)
{
    foreach (var filePath in Directory.GetFiles(directory))
    {
        yield return (RasterImage)Image.Load(filePath);
    }
}
See Also