public static PredefinedColorsQuantizer FromCustomFunction(
Func<Color32, Color32> quantizingFunction,
Color32 backColor,
KnownPixelFormat pixelFormatHint = KnownPixelFormat.Format24bppRgb,
byte alphaThreshold = 0
)
Public Shared Function FromCustomFunction (
quantizingFunction As Func(Of Color32, Color32),
backColor As Color32,
Optional pixelFormatHint As KnownPixelFormat = KnownPixelFormat.Format24bppRgb,
Optional alphaThreshold As Byte = 0
) As PredefinedColorsQuantizer
public:
static PredefinedColorsQuantizer^ FromCustomFunction(
Func<Color32, Color32>^ quantizingFunction,
Color32 backColor,
KnownPixelFormat pixelFormatHint = KnownPixelFormat::Format24bppRgb,
unsigned char alphaThreshold = 0
)
static member FromCustomFunction :
quantizingFunction : Func<Color32, Color32> *
backColor : Color32 *
?pixelFormatHint : KnownPixelFormat *
?alphaThreshold : byte
(* Defaults:
let _pixelFormatHint = defaultArg pixelFormatHint KnownPixelFormat.Format24bppRgb
let _alphaThreshold = defaultArg alphaThreshold 0
*)
-> 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 never calls the quantizingFunction delegate with a color with alpha. Depending on alphaThreshold either a completely transparent color will be returned or the color will be blended with backColor before invoking the delegate. In order to allow invoking quantizingFunction with alpha colors use the FromCustomFunction(FuncColor32, Color32, KnownPixelFormat) or FromCustomFunction(FuncColor32, Color32, Color32, Byte, Boolean, KnownPixelFormat) overloads instead.
public static IReadWriteBitmapData ToGrayscaleOpaque(IReadWriteBitmapData source, Color32 backColor = default)
{
IQuantizer quantizer = PredefinedColorsQuantizer.FromCustomFunction(c => c.ToGray(), backColor);
// a.) this solution returns a new bitmap data and does not change the original one:
return source.Clone(KnownPixelFormat.Format24bppRgb, 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 |
---|---|
|
|
|
|