ImageExtensionsSaveAsGif Method (Image, Stream, IQuantizer, IDitherer)

KGy SOFT Drawing Libraries Help
Saves the specified image using the built-in GIF encoder if available in the current operating system. Unlike the Save(Stream, ImageFormat) method, this one supports every PixelFormat.
See the Remarks section for details.

Namespace:  KGySoft.Drawing
Assembly:  KGySoft.Drawing (in KGySoft.Drawing.dll) Version: 5.1.0
Syntax

public static void SaveAsGif(
	this Image image,
	Stream stream,
	IQuantizer quantizer = null,
	IDitherer ditherer = null
)

Parameters

image
Type: System.DrawingImage
The image to save. If image contains multiple images other than animated GIF frames, then only the current image will be saved.
stream
Type: System.IOStream
The stream to save the image into.
quantizer (Optional)
Type: KGySoft.Drawing.ImagingIQuantizer
If image is a non-indexed one, then specifies the quantizer to be used to determine the colors of the saved image. If , then the target colors will be optimized for the actual colors in the image. This parameter is optional.
Default value: .
ditherer (Optional)
Type: KGySoft.Drawing.ImagingIDitherer
If a quantization has to be performed can specifies the ditherer to be used. If , then no dithering will be performed. This parameter is optional.
Default value: .

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type Image. When you use instance method syntax to call this method, omit the first parameter. For more information, see Extension Methods (Visual Basic) or Extension Methods (C# Programming Guide).
Exceptions

ExceptionCondition
ArgumentNullExceptionimage or stream is .
InvalidOperationExceptionNo built-in encoder was found or the saving fails in the current operating system.
Remarks

The image can only be saved if a built-in GIF encoder is available in the current operating system.

If image is an animated GIF, then the whole animation will be saved (can depend on the operating system).

The image will be saved always with a Format8bppIndexed format, though the palette can have less than 256 colors.

The GIF format supports single bit transparency only.

Images with PixelFormats other than Format8bppIndexed are converted to Format8bppIndexed before saving (including other indexed formats); otherwise, the built-in GIF encoder (at least on Windows) would save the image with a fixed palette and transparency would be lost.

Note Note
On Linux the built-in GIF encoder turns transparent palette entries opaque.

If quantizer is  and image has a non-indexed pixel format, then a quantizer is automatically selected for optimizing the palette. The auto selected quantizer is obtained by the PredefinedColorsQuantizer.Grayscale method for the Format16bppGrayScale pixel format, and by the OptimizedPaletteQuantizer.Wu method for any other pixel formats.

If ditherer is , then no ditherer will be auto-selected for the quantization.

See Also

Reference