public static PredefinedColorsQuantizer BlackAndWhite(
Color backColor = default,
byte whiteThreshold = 128
)
Public Shared Function BlackAndWhite (
Optional backColor As Color = Nothing,
Optional whiteThreshold As Byte = 128
) As PredefinedColorsQuantizer
public:
static PredefinedColorsQuantizer^ BlackAndWhite(
Color backColor = Color(),
unsigned char whiteThreshold = 128
)
static member BlackAndWhite :
?backColor : Color *
?whiteThreshold : byte
(* Defaults:
let _backColor = defaultArg backColor new Color()
let _whiteThreshold = defaultArg whiteThreshold 128
*)
-> PredefinedColorsQuantizer
If the returned quantizer is combined with an ErrorDiffusionDitherer, then the effect of the whiteThreshold parameter is mostly compensated. Other ditherers preserve the effect of the whiteThreshold parameter.
This quantizer fits well for the Format1bppIndexed pixel format.
public static IReadWriteBitmapData ToBlackAndWhite(IReadWriteBitmapData source, Color backColor = default,
byte whiteThreshold = 128, IDitherer ditherer = null)
{
IQuantizer quantizer = PredefinedColorsQuantizer.BlackAndWhite(backColor, whiteThreshold);
// a.) this solution returns a new bitmap data and does not change the original one:
return source.Clone(KnownPixelFormat.Format1bppIndexed, 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 |
---|---|
|
|
|
|
|
|
|
|