public static PredefinedColorsQuantizer SystemDefault4BppPalette(
Color32 backColor = default,
byte alphaThreshold = 128
)Public Shared Function SystemDefault4BppPalette (
Optional backColor As Color32 = Nothing,
Optional alphaThreshold As Byte = 128
) As PredefinedColorsQuantizerpublic:
static PredefinedColorsQuantizer^ SystemDefault4BppPalette(
Color32 backColor = Color32(),
unsigned char alphaThreshold = 128
)static member SystemDefault4BppPalette :
?backColor : Color32 *
?alphaThreshold : byte
(* Defaults:
let _backColor = defaultArg backColor new Color32()
let _alphaThreshold = defaultArg alphaThreshold 128
*)
-> PredefinedColorsQuantizer The returned PredefinedColorsQuantizer instance can return up to 16 colors.
This quantizer fits well for the Format4bppIndexed pixel format.
The palette of this quantizer does not contain transparent entries. The palette consists of the 16 standard basic sRGB colors
public static IReadWriteBitmapData ToDefault4Bpp(IReadWriteBitmapData source, Color32 backColor = default, IDitherer ditherer = null)
{
IQuantizer quantizer = PredefinedColorsQuantizer.SystemDefault4BppPalette(backColor);
// a.) this solution returns a new bitmap data and does not change the original one:
return source.Clone(KnownPixelFormat.Format8bppIndexed, quantizer, ditherer);
// b.) when converting to Format4bppIndexed format without dithering, this produces the same result:
if (ditherer == null)
return source.Clone(KnownPixelFormat.Format4bppIndexed, 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 |
|---|---|
|
|
|
|
|
|