OptimizedPaletteQuantizerOctree Method

KGy SOFT Drawing Libraries Help
Gets an OptimizedPaletteQuantizer instance that quantizes colors of an image using the Octree quantizing algorithm.
See the Examples section for an example, and the Remarks section of the OptimizedPaletteQuantizer for details and results comparison with the other algorithms.

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

public static OptimizedPaletteQuantizer Octree(
	int maxColors = 256,
	Color backColor = null,
	byte alphaThreshold = 128
)

Parameters

maxColors (Optional)
Type: SystemInt32
The upper limit of generated colors. Must be between 2 and 256, inclusive bounds. This parameter is optional.
Default value: 256.
backColor (Optional)
Type: System.DrawingColor
Colors with alpha above the alphaThreshold will be blended with this color before quantizing. The Color.A property of the background color is ignored. This parameter is optional.
Default value: Empty, which has the same RGB values as Black.
alphaThreshold (Optional)
Type: SystemByte
Specifies a threshold value for the Color.A property, under which a quantized color is considered transparent. If 0, then the quantized colors will never be transparent. This parameter is optional.
Default value: 128.

Return Value

Type: OptimizedPaletteQuantizer
A OptimizedPaletteQuantizer instance that quantizes colors of an image using the Octree quantizing algorithm.
Exceptions

ExceptionCondition
ArgumentOutOfRangeExceptionmaxColors must be between 2 and 256, inclusive bounds.
Examples

The following example demonstrates how to use the quantizer returned by this method:
C#
Bitmap bmpOriginal = Icons.Shield.ExtractBitmap(new Size(256, 256));
bmpOriginal.SaveAsPng(@"c:\temp\original.png");

IQuantizer quantizer = OptimizedPaletteQuantizer.Octree(256);
Bitmap bmpConverted = bmpOriginal.ConvertPixelFormat(PixelFormat.Format8bppIndexed, quantizer);
bmpConverted.SaveAsGif(@"c:\temp\converted.gif");

The example above produces the following result:

original.pngShield icon with transparent background
converted.gifShield icon quantized to 256 colors using the Octree algorithm

Tip Tip
For more image examples and side-by-side comparison with the other algorithms see the Remarks section of the OptimizedPaletteQuantizer class.
See Also

Reference