public static PredefinedColorsQuantizer Grayscale(
Color backColor = default
)
Public Shared Function Grayscale (
Optional backColor As Color = Nothing
) As PredefinedColorsQuantizer
public:
static PredefinedColorsQuantizer^ Grayscale(
Color backColor = Color()
)
static member Grayscale :
?backColor : Color
(* Defaults:
let _backColor = defaultArg backColor new Color()
*)
-> PredefinedColorsQuantizer
The returned quantizer uses direct mapping to grayscale colors based on human perception, which makes quantization very fast while it is very accurate at the same time.
The returned PredefinedColorsQuantizer instance can return up to 256 possible shades of gray.
The palette of this quantizer does not contain the transparent color. To make a bitmap data grayscale with transparency you can use the ToGrayscale and MakeGrayscale extension methods.
This quantizer fits well for the Format8bppIndexed pixel format.
public static IReadWriteBitmapData ToGrayscale(IReadWriteBitmapData source, Color backColor = default)
{
IQuantizer quantizer = PredefinedColorsQuantizer.Grayscale(backColor);
// a.) this solution returns a new bitmap data and does not change the original one:
return source.Clone(KnownPixelFormat.Format8bppIndexed, quantizer);
// b.) alternatively, you can perform the quantization directly on the source bitmap data:
source.Quantize(quantizer);
return source;
}
The example above may produce the following results:
Original image | Quantized image |
---|---|
|
|
|
|