ImageExtensionsSaveAsGif(Image, Stream, IQuantizer, IDitherer) Method

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.

Definition

Namespace: KGySoft.Drawing
Assembly: KGySoft.Drawing (in KGySoft.Drawing.dll) Version: 8.1.0
C#
public static void SaveAsGif(
	this Image image,
	Stream stream,
	IQuantizer? quantizer = null,
	IDitherer? ditherer = null
)

Parameters

image  Image
The image to save. If image contains multiple images other than animated GIF frames, then only the current image will be saved.
stream  Stream
The stream to save the image into.
quantizer  IQuantizer  (Optional)
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  IDitherer  (Optional)
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).

Remarks

  Note

This method adjusts the degree of parallelization automatically, blocks the caller, and does not support cancellation or reporting progress. Use the GifEncoder.BeginEncodeImage or GifEncoder.EncodeImageAsync (in .NET Framework 4.0 and above) methods for asynchronous call and to adjust parallelization, set up cancellation and for reporting progress.

The image can be saved even without a registered GIF encoder in the current operating system. To save the GIF image, the GifEncoder class is used internally.

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

The GIF format supports single bit transparency only.

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.

Exceptions

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

See Also