PredefinedColorsQuantizerRgb565 Method

KGy SOFT Drawing Libraries Help
Gets a PredefinedColorsQuantizer instance that quantizes colors to 16-bit ones where red, green and blue components are encoded in 5, 6 and 5 bits, respectively.

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

public static PredefinedColorsQuantizer Rgb565(
	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 16-bit ones where red, green and blue components are encoded in 5, 6 and 5 bits, respectively.
Remarks

The returned PredefinedColorsQuantizer instance can return up to 65,536 colors.

This quantizer fits well for Bitmaps with Format16bppRgb565 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 ToRgb565(Bitmap source, Color backColor = default, IDitherer ditherer = null)
{
    IQuantizer quantizer = PredefinedColorsQuantizer.Rgb565(backColor);

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

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

    // c.) alternatively, you can perform the quantization directly on the source bitmap:
    if (ditherer == null)
        source.Quantize(quantizer);
    else
        source.Dither(quantizer, ditherer);
    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 RGB565 pixel format and black background
Default optional parameter values (black background)

Color hues with RGB565 pixel format and silver background
Silver background

Color hues with RGB565 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 RGB565 pixel format and black background
Default optional parameter values (black background)

Shield icon with RGB565 pixel format and silver background
Silver background

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

See Also

Reference