InterleavedGradientNoiseDitherer(Single) Constructor

Initializes a new instance of the InterleavedGradientNoiseDitherer class.

Definition

Namespace: KGySoft.Drawing.Imaging
Assembly: KGySoft.Drawing.Core (in KGySoft.Drawing.Core.dll) Version: 8.2.0
C#
public InterleavedGradientNoiseDitherer(
	float strength = 0f
)

Parameters

strength  Single  (Optional)
The strength of the dithering effect between 0 and 1 (inclusive bounds). Specify 0 to use an auto value for each dithering session based on the used quantizer.
See the Remarks section of the OrderedDitherer.ConfigureStrength method for more details and some examples regarding dithering strength. The same applies also for the InterleavedGradientNoiseDitherer class. This parameter is optional.
Default value: 0.

Example

The following example demonstrates how to use the InterleavedGradientNoiseDitherer class.
C#
public static IReadWriteBitmapData ToDitheredInterleavedGradientNoise(IReadWriteBitmapData source, IQuantizer quantizer)
{
    IDitherer ditherer = new InterleavedGradientNoiseDitherer();

    // a.) this solution returns a new bitmap data and does not change the original one:
    return source.Clone(quantizer.PixelFormatHint, quantizer, ditherer);

    // b.) alternatively, you can perform the dithering directly on the source bitmap data:
    source.Dither(quantizer, ditherer);
    return source;
}

The example above may produce the following results:

Original image
Quantized and dithered image

Color hues with alpha gradient
Color hues with alpha gradient

Grayscale color shades with different bit depths
Grayscale color shades

Grayscale color shades with black and white palette using interleaved gradient noise dithering
Quantizing with black and white palette

Exceptions

ArgumentOutOfRangeExceptionstrength must be between 0 and 1, inclusive bounds.

See Also