PredefinedColorsQuantizerRgb888 Method

KGy SOFT Drawing Libraries Help
Gets a PredefinedColorsQuantizer instance that quantizes colors to 24-bit ones where each color component is encoded in 8 bits.
See the Remarks section for details and some examples.

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

public static PredefinedColorsQuantizer Rgb888(
	Color backColor = null
)

Parameters

backColor (Optional)
Type: System.DrawingColor
Colors with alpha (transparency) will be blended with this color before quantization. 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.

Return Value

Type: PredefinedColorsQuantizer
A PredefinedColorsQuantizer instance that quantizes colors to 24-bit ones where each color component is encoded in 8 bits.
Remarks

The returned PredefinedColorsQuantizer instance can return up to 2563 (16,777,216) colors. It practically just removes transparency and does not change colors without alpha.

This quantizer fits well for Bitmaps with Format24bppRgb pixel format.

Note Note
For more information about the possible usable PixelFormats on different platforms see the Remarks section of the ConvertPixelFormat extension method.
Examples

The following example demonstrates how to use the quantizer returned by this method:
C#
public static Bitmap ToRgb888(Bitmap source, Color backColor = default)
{
    IQuantizer quantizer = PredefinedColorsQuantizer.Rgb888(backColor);

    // a.) this solution returns a new bitmap and does not change the original one:
    return source.ConvertPixelFormat(PixelFormat.Format24bppRgb, quantizer);

    // b.) when converting to Format24bppRgb format, this produces the same result:
    return source.ConvertPixelFormat(PixelFormat.Format24bppRgb, backColor);

    // c.) alternatively, you can perform the quantization directly on the source bitmap:
    source.Quantize(quantizer);
    return source;
}

The example above may produce the following results:

Original imageQuantized image

Color hues with alpha gradient
Color hues with alpha gradient

Color hues with black background
Default (black) background

Color hues with silver background
Silver background

Shield icon with transparent background
Shield icon with transparency

Shield icon with black background
Default (black) background

Shield icon with silver background
Silver background

See Also

Reference