DrawingOptionsDitherer Property

Gets or sets an IDitherer instance to use when drawing shapes.
Default value: .

See the online help for an example with images.

Definition

Namespace: KGySoft.Drawing.Shapes
Assembly: KGySoft.Drawing.Core (in KGySoft.Drawing.Core.dll) Version: 9.0.0
C#
public IDitherer? Ditherer { get; set; }

Property Value

IDitherer

Remarks

If the target IReadWriteBitmapData does not support the color depth of the drawn shape, or when Quantizer is also set, setting a ditherer can help to preserve the original details.

If Quantizer is , and the target IReadWriteBitmapData is not a low-color bitmap, then this property might be ignored.

Examples

The following example demonstrates how to draw a shape with dithering:

C#
public IReadWriteBitmapData CreateBlackAndWhiteDrawing(IDitherer? ditherer)
{
    // Creating a 1bpp image, which has a black white palette by default
    IReadWriteBitmapData bmp = BitmapDataFactory.CreateBitmapData(100, 100, KnownPixelFormat.Format1bppIndexed);

    // Clearing the image with Cyan, using the ditherer
    bmp.Clear(Color.Cyan, ditherer);

    // Specifying a path with a star shape, translated to the center of the 100 x 100 bitmap
    var path = new Path(false)
        .TransformTranslation(1, 5)
        .AddPolygon(new(50, 0), new(79, 90), new(2, 35), new(97, 35), new(21, 90));

    // Filling the star shape with a blue brush
    bmp.FillPath(Color.Blue, path, new DrawingOptions { Ditherer = ditherer });

    return bmp;
}

The example above may produce the following results:

DescriptionImage Example
Ditherer is . The colors are automatically quantized to the black and white target. Cyan becomes white, whereas blue becomes black.Shape drawing with black and white quantizing.
Using InterleavedGradientNoiseDitherer. The shades of cyan and blue appear in dithering patterns.Shape drawing with black and white quantizing, using interleaved gradient noise dithering.
Using BlueNoise dithering. The shades of cyan and blue appear in dithering patterns.Shape drawing with black and white quantizing, using blue noise dithering.

See Also