Tip
- Use the static properties to perform dithering with predefined patterns.
- See the Remarks section of the OrderedDitherer class for more details and image examples.
public OrderedDitherer(
byte[,] matrix,
float strength = 0f
)
Public Sub New (
matrix As Byte(,),
Optional strength As Single = 0F
)
public:
OrderedDitherer(
array<unsigned char,2>^ matrix,
float strength = 0f
)
new :
matrix : byte[,] *
?strength : float32
(* Defaults:
let _strength = defaultArg strength 0f
*)
-> OrderedDitherer
public static IReadWriteBitmapData ToCustomDithered(IReadWriteBitmapData source, IQuantizer quantizer)
{
// Using a dotted halftone pattern. As it uses only 11 values in a 7x7 matrix it is much less optimal
// than the DottedHalftone property but demonstrates the behavior of the ordered dithering quite well.
byte[,] matrix =
{
{ 0, 2, 4, 5, 4, 2, 1 },
{ 2, 3, 6, 7, 6, 3, 2 },
{ 4, 6, 8, 9, 8, 6, 4 },
{ 5, 7, 9, 10, 9, 7, 5 },
{ 4, 6, 8, 9, 8, 6, 4 },
{ 2, 3, 6, 7, 6, 3, 2 },
{ 1, 2, 4, 5, 4, 2, 1 },
};
IDitherer ditherer = new OrderedDitherer(matrix);
// 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 |
---|---|
|
|
|
|
ArgumentNullException | matrix is . |
ArgumentException | matrix is empty. |
ArgumentOutOfRangeException | strength must be between 0 and 1, inclusive bounds. |