public static PredefinedColorsQuantizer FromCustomPalette(
Palette palette
)Public Shared Function FromCustomPalette (
palette As Palette
) As PredefinedColorsQuantizerpublic:
static PredefinedColorsQuantizer^ FromCustomPalette(
Palette^ palette
)static member FromCustomPalette :
palette : Palette -> PredefinedColorsQuantizer 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 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 |
|---|---|
|
|
|
|
|
|
|
|