PredefinedColorsQuantizerRgb332 Method
Gets a
PredefinedColorsQuantizer instance that can quantize colors to 8-bit ones where red,
green and blue components are encoded in 3, 3 and 2 bits, respectively.
Namespace: KGySoft.Drawing.ImagingAssembly: KGySoft.Drawing.Core (in KGySoft.Drawing.Core.dll) Version: 9.0.0
public static PredefinedColorsQuantizer Rgb332(
Color32 backColor = default,
bool directMapping = false,
byte alphaThreshold = 128
)
Public Shared Function Rgb332 (
Optional backColor As Color32 = Nothing,
Optional directMapping As Boolean = false,
Optional alphaThreshold As Byte = 128
) As PredefinedColorsQuantizer
public:
static PredefinedColorsQuantizer^ Rgb332(
Color32 backColor = Color32(),
bool directMapping = false,
unsigned char alphaThreshold = 128
)
static member Rgb332 :
?backColor : Color32 *
?directMapping : bool *
?alphaThreshold : byte
(* Defaults:
let _backColor = defaultArg backColor new Color32()
let _directMapping = defaultArg directMapping false
let _alphaThreshold = defaultArg alphaThreshold 128
*)
-> PredefinedColorsQuantizer
- 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. - directMapping Boolean (Optional)
- to map any color directly to an index instead of searching for a nearest color,
which is very fast but without dithering may end up in a noticeably poorer result and higher contrast;
to perform a lookup to determine nearest colors, which may be slower but more accurate. This parameter is optional.
Default value: . - 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.
PredefinedColorsQuantizerA
PredefinedColorsQuantizer instance that can quantize colors to 8-bit ones where red,
green and blue components are encoded in 3, 3 and 2 bits, respectively.
If directMapping is , then the result of the quantizing may have a higher contrast than without direct color mapping,
though this can be compensated if the returned quantizer is combined with an ErrorDiffusionDitherer. Other ditherers preserve the effect of the directMapping parameter.
The returned PredefinedColorsQuantizer instance can return up to 256 colors.
This quantizer fits well for the Format8bppIndexed pixel format.
The palette of this quantizer does not contain the transparent color.
The following example demonstrates how to use the quantizer returned by this method:
public static IReadWriteBitmapData ToRgb332(IReadWriteBitmapData source, Color32 backColor = default, bool directMapping = false, IDitherer ditherer = null)
{
IQuantizer quantizer = PredefinedColorsQuantizer.Rgb332(backColor, directMapping);
// a.) this solution returns a new bitmap data and does not change the original one:
return source.Clone(KnownPixelFormat.Format8bppIndexed, quantizer, ditherer);
// b.) 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
|  Default optional parameter values (black background, nearest color lookup)
 Silver background, nearest color lookup
 Silver background, direct color mapping
 Silver background, direct color mapping, Bayer 8x8 dithering
|
 Grayscale color shades
|  Nearest color lookup
 Direct color mapping
 Nearest color lookup, Bayer 8x8 dithering
 Direct color mapping, Bayer 8x8 dithering
|
 Shield icon with transparency
|  Default optional parameter values (nearest color lookup)
 Silver background, nearest color lookup
 Silver background, direct color mapping
 Silver background, direct color mapping, Floyd-Steinberg dithering
|
 Original test image "Lena"
|  Nearest color lookup
 Direct color mapping
 Direct color mapping, Floyd-Steinberg dithering
|