RandomNoiseDitherer(Single, NullableInt32) Constructor

Initializes a new instance of the RandomNoiseDitherer class.

Definition

Namespace: KGySoft.Drawing.Imaging
Assembly: KGySoft.Drawing.Core (in KGySoft.Drawing.Core.dll) Version: 8.2.0
C#
public RandomNoiseDitherer(
	float strength = 0f,
	int? seed = null
)

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 RandomNoiseDitherer class. This parameter is optional.
Default value: 0.
seed  NullableInt32  (Optional)
If , then a ThreadSafeRandom instance will be used internally with a time-dependent seed value, and the dithering session will allow parallel processing. If not , then a Random instance will be created for each dithering session with the specified seed, and the dithering session will not allow parallel processing.

Example

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

    // 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 random noise dithering
Quantizing with black and white palette

Exceptions

ArgumentOutOfRangeExceptionstrength must be between 0 and 1, inclusive bounds.

See Also