PredefinedColorsQuantizerRgb555 Method

Gets a PredefinedColorsQuantizer instance that can quantize colors to 16-bit ones where each color component is encoded in 5 bits.

See the online help for an example with images.

Definition

Namespace: KGySoft.Drawing.Imaging
Assembly: KGySoft.Drawing.Core (in KGySoft.Drawing.Core.dll) Version: 9.0.0
C#
public static PredefinedColorsQuantizer Rgb555(
	Color32 backColor = default,
	byte alphaThreshold = 128
)

Parameters

backColor  Color32  (Optional)
Colors with alpha (transparency) will be blended with this color before quantizing. The Color32.A field of the background color is ignored. This parameter is optional.
Default value: The default value of the Color32 type, which has the same RGB values as Color.Black.
alphaThreshold  Byte  (Optional)
Specifies a threshold value for the Color32.A field, under which a quantized color is considered completely transparent. Though the quantizer returned from this method never returns alpha colors, it can be relevant in some cases, for example when drawing a partially transparent bitmap onto a solid background. The source pixels, whose alpha value is below the alphaThreshold will be skipped, whereas alpha pixels with higher opacity will be blended with the specified backColor. This parameter is optional.
Default value: 128.

Return Value

PredefinedColorsQuantizer
A PredefinedColorsQuantizer instance that can quantize colors to 16-bit ones where each color component is encoded in 5 bits.

Remarks

The returned PredefinedColorsQuantizer instance can return up to 32,768 colors.

This quantizer fits well for the Format16bppRgb555 pixel format.

Examples

The following example demonstrates how to use the quantizer returned by this method:
C#
public static IReadWriteBitmapData ToRgb555(IReadWriteBitmapData source, Color32 backColor = default, IDitherer ditherer = null)
{
    IQuantizer quantizer = PredefinedColorsQuantizer.Rgb555(backColor);

    // a.) this solution returns a new bitmap data and does not change the original one:
    return source.Clone(KnownPixelFormat.Format16bppRgb555, quantizer, ditherer);

    // b.) when converting to Format16bppRgb555 format without dithering, this produces the same result:
    if (ditherer == null)
        return source.Clone(KnownPixelFormat.Format16bppRgb555, backColor);

    // c.) alternatively, you can perform the quantizing directly on the source bitmap data:
    if (ditherer == null)
        source.Quantize(quantizer);
    else
        source.Dither(quantizer, ditherer);
    return source;
}

The example above may produce the following results:

Original image
Quantized image

Color hues with alpha gradient
Color hues with alpha gradient

Color hues with RGB555 pixel format and black background
Default optional parameter values (black background)

Color hues with RGB555 pixel format and silver background
Silver background

Color hues with RGB555 pixel format, silver background and Bayer 8x8 ordered dithering
Silver background, Bayer 8x8 dithering

Shield icon with transparent background
Shield icon with transparency

Shield icon with RGB555 pixel format and black background
Default optional parameter values (black background)

Shield icon with RGB555 pixel format and silver background
Silver background

Shield icon with RGB555 pixel format, silver background and Floyd-Steinberg dithering
Silver background, Floyd-Steinberg dithering

See Also