Tip
- Use the static properties to perform dithering with predefined filters.
- See the Remarks section of the ErrorDiffusionDitherer class for more details and image examples.
public ErrorDiffusionDitherer(
byte[,] matrix,
int divisor,
int matrixFirstPixelIndex,
bool serpentineProcessing = false,
bool? byBrightness = null
)
Public Sub New (
matrix As Byte(,),
divisor As Integer,
matrixFirstPixelIndex As Integer,
Optional serpentineProcessing As Boolean = false,
Optional byBrightness As Boolean? = Nothing
)
public:
ErrorDiffusionDitherer(
array<unsigned char,2>^ matrix,
int divisor,
int matrixFirstPixelIndex,
bool serpentineProcessing = false,
Nullable<bool> byBrightness = nullptr
)
new :
matrix : byte[,] *
divisor : int *
matrixFirstPixelIndex : int *
?serpentineProcessing : bool *
?byBrightness : Nullable<bool>
(* Defaults:
let _serpentineProcessing = defaultArg serpentineProcessing false
let _byBrightness = defaultArg byBrightness null
*)
-> ErrorDiffusionDitherer
public static IReadWriteBitmapData ToCustomDithered(IReadWriteBitmapData source, IQuantizer quantizer)
{
// This is actually the Fan dithering (by Zhihang Fan), and uses the same coefficients
// as the Floyd-Steinberg dithering in a slightly different arrangement:
byte[,] matrix =
{
{ 0, 0, 0, 7 },
{ 1, 3, 5, 0 },
};
// The matrix values will be divided by this value to determine the portion
// of the quantization error to propagate to neighboring pixels:
int divisor = 16;
// The current pixel to be processed is always one pixel left from this index.
// This also means that if larger than 1, then some error is propagated also towards the
// (bottom-)left direction. For the matrix above value "3" means that whenever a pixel is
// processed, 7/16 of the error is propagated to the right, 1/16 and 3/16 to the
// bottom-left direction and 5/16 one pixel down from the current pixel.
int firstPixelIndex = 3;
IDitherer ditherer = new ErrorDiffusionDitherer(matrix, divisor, firstPixelIndex);
// 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 |
---|---|
|
|
|
|