public static PredefinedColorsQuantizer SystemDefault8BppPalette(
Color32 backColor = default,
byte alphaThreshold = 128
)
Public Shared Function SystemDefault8BppPalette (
Optional backColor As Color32 = Nothing,
Optional alphaThreshold As Byte = 128
) As PredefinedColorsQuantizer
public:
static PredefinedColorsQuantizer^ SystemDefault8BppPalette(
Color32 backColor = Color32(),
unsigned char alphaThreshold = 128
)
static member SystemDefault8BppPalette :
?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 256 colors. Actually this amount is somewhat smaller because of some redundant entries in the palette.
This quantizer fits well for the Format8bppIndexed pixel format.
The palette of this quantizer contains transparent entries.
public static IReadWriteBitmapData ToDefault8Bpp(IReadWriteBitmapData source, Color32 backColor = default,
byte alphaThreshold = 128, IDitherer ditherer = null)
{
IQuantizer quantizer = PredefinedColorsQuantizer.SystemDefault8BppPalette(backColor, alphaThreshold);
// 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 Format8bppIndexed format without dithering, this produces the same result:
if (ditherer == null)
return source.Clone(KnownPixelFormat.Format8bppIndexed, backColor, alphaThreshold);
// 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 |
---|---|
|
|
|
|
|
|
|