public static PredefinedColorsQuantizer Grayscale4(
Color backColor = default,
bool directMapping = false
)
Public Shared Function Grayscale4 (
Optional backColor As Color = Nothing,
Optional directMapping As Boolean = false
) As PredefinedColorsQuantizer
public:
static PredefinedColorsQuantizer^ Grayscale4(
Color backColor = Color(),
bool directMapping = false
)
static member Grayscale4 :
?backColor : Color *
?directMapping : bool
(* Defaults:
let _backColor = defaultArg backColor new Color()
let _directMapping = defaultArg directMapping false
*)
-> PredefinedColorsQuantizer
If directMapping is , then the result of the quantization 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 4 possible shades of gray.
This quantizer fits well for the Format4bppIndexed pixel format, though only 4 palette entries are used instead of the possible maximum of 16.
public static IReadWriteBitmapData ToGrayscale4(IReadWriteBitmapData source, Color backColor = default, bool directMapping = false, IDitherer ditherer = null)
{
IQuantizer quantizer = PredefinedColorsQuantizer.Grayscale4(backColor, directMapping);
// 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 |
---|---|
|
|
| |
|
|
|