public static PredefinedColorsQuantizer FromCustomFunction(
Func<Color32, Color32> quantizingFunction,
KnownPixelFormat pixelFormatHint = KnownPixelFormat.Format32bppArgb
)
Public Shared Function FromCustomFunction (
quantizingFunction As Func(Of Color32, Color32),
Optional pixelFormatHint As KnownPixelFormat = KnownPixelFormat.Format32bppArgb
) As PredefinedColorsQuantizer
public:
static PredefinedColorsQuantizer^ FromCustomFunction(
Func<Color32, Color32>^ quantizingFunction,
KnownPixelFormat pixelFormatHint = KnownPixelFormat::Format32bppArgb
)
static member FromCustomFunction :
quantizingFunction : Func<Color32, Color32> *
?pixelFormatHint : KnownPixelFormat
(* Defaults:
let _pixelFormatHint = defaultArg pixelFormatHint KnownPixelFormat.Format32bppArgb
*)
-> PredefinedColorsQuantizer
The quantizer returned by this method does not have a palette. If you need to create an indexed result using a custom mapping function that uses up to 256 different colors, then create a Palette instance specifying a custom function and call the FromCustomPalette(Palette) method instead.
This overload always calls the quantizingFunction delegate without preprocessing the input colors. In order to pass only opaque colors to the quantizingFunction delegate use the FromCustomFunction(FuncColor32, Color32, Color, KnownPixelFormat, Byte) overload instead.
This overload always creates a quantizer with black BackColor and zero AlphaThreshold. If quantizingFunction can return colors with alpha, then the background color and alpha threshold are relevant only when this quantizer is used together with an IDitherer, which does not support partial transparency. Use the FromCustomFunction(FuncColor32, Color32, Color, Byte, Boolean, KnownPixelFormat) overload to specify the BackColor and AlphaThreshold properties.
public static IReadWriteBitmapData ToGrayscalePreserveAlpha(IReadWriteBitmapData source)
{
IQuantizer quantizer = PredefinedColorsQuantizer.FromCustomFunction(c => c.ToGray());
// a.) this solution returns a new bitmap data and does not change the original one:
return source.Clone(KnownPixelFormat.Format32bppArgb, 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 |
---|---|
|
|
|
|