public static PredefinedColorsQuantizer Grayscale(
Color32 backColor = default,
byte alphaThreshold = 128
)
Public Shared Function Grayscale (
Optional backColor As Color32 = Nothing,
Optional alphaThreshold As Byte = 128
) As PredefinedColorsQuantizer
public:
static PredefinedColorsQuantizer^ Grayscale(
Color32 backColor = Color32(),
unsigned char alphaThreshold = 128
)
static member Grayscale :
?backColor : Color32 *
?alphaThreshold : byte
(* Defaults:
let _backColor = defaultArg backColor new Color32()
let _alphaThreshold = defaultArg alphaThreshold 128
*)
-> PredefinedColorsQuantizer
The returned quantizer uses direct mapping to grayscale colors based on human perception, which makes quantizing 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 and Format8bppGrayScale pixel formats.
public static IReadWriteBitmapData ToGrayscale(IReadWriteBitmapData source, Color32 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 quantizing directly on the source bitmap data:
source.Quantize(quantizer);
return source;
}
The example above may produce the following results:
Original image | Quantized image |
---|---|
|
|
|
|