public static PredefinedColorsQuantizer FromCustomPalette(
Color[] palette,
Color backColor = default,
byte alphaThreshold = 128
)
Public Shared Function FromCustomPalette (
palette As Color(),
Optional backColor As Color = Nothing,
Optional alphaThreshold As Byte = 128
) As PredefinedColorsQuantizer
public:
static PredefinedColorsQuantizer^ FromCustomPalette(
array<Color>^ palette,
Color backColor = Color(),
unsigned char alphaThreshold = 128
)
static member FromCustomPalette :
palette : Color[] *
?backColor : Color *
?alphaThreshold : byte
(* Defaults:
let _backColor = defaultArg backColor new Color()
let _alphaThreshold = defaultArg alphaThreshold 128
*)
-> PredefinedColorsQuantizer
The PredefinedColorsQuantizer instance returned by this method will use a Palette internally, created from the colors specified in the palette parameter. When quantizing, best matching colors might be looked up sequentially and results might be cached.
If a color to be quantized can be mapped to a color index directly, then create a Palette instance explicitly, specifying the custom mapping logic and use the FromCustomPalette(Palette) overload instead.
If a color to be quantized can be transformed to a result color directly, and the quantized result is not needed to be an indexed image, then use the FromCustomFunction overloads instead.
public static IReadWriteBitmapData ToRgb111(IReadWriteBitmapData source,
Color backColor = default, IDitherer ditherer = null, WorkingColorSpace colorSpace = default)
{
Color[] colors =
{
Color.Black, Color.Red, Color.Lime, Color.Blue,
Color.Magenta, Color.Yellow, Color.Cyan, Color.White
};
IQuantizer quantizer = PredefinedColorsQuantizer.FromCustomPalette(new Palette(colors, colorSpace, backColor));
// a.) this solution returns a new bitmap data and does not change the original one:
return source.Clone(KnownPixelFormat.Format4bppIndexed, quantizer, ditherer);
// b.) alternatively, you can perform the quantization 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 |
---|---|
|
|
|
|
|
|
|
|