BitmapExtensionsQuantize Method

KGy SOFT Drawing Libraries Help
Quantizes a bitmap using the specified quantizer (reduces the number of colors).
See the Remarks section for details.

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

public static void Quantize(
	this Bitmap bitmap,
	IQuantizer quantizer
)

Parameters

bitmap
Type: System.DrawingBitmap
A Bitmap instance to be quantized.
quantizer
Type: KGySoft.Drawing.ImagingIQuantizer
An IQuantizer implementation to be used for quantizing the specified bitmap.

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type Bitmap. 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
ArgumentNullExceptionbitmap or quantizer is .
InvalidOperationExceptionThe quantizer's Initialize method returned .
Remarks

This method quantizes bitmap in place (its original content will be overwritten). To return a new instance use the ConvertPixelFormat extension method instead.

If the PixelFormat or the palette of bitmap is not compatible with the colors of the specified quantizer, then the result may not be correct.

If bitmap has already the same set of colors that the specified quantizer, then it can happen that calling this method does not change bitmap at all.

Tip Tip
  • To use predefined colors or custom quantization functions use the static methods of the PredefinedColorsQuantizer class.
    See the Remarks section of its members for details and examples.
  • To use an optimized palette of up to 256 colors adjusted for bitmap see the OptimizedPaletteQuantizer class.
See Also

Reference