Dithering

DynamicPDF Rasterizer supports dithering. Dithering is a computer graphics technique that reduces the visual side effects of color quantization. A quantized image may contain flat areas and patches of color that may significantly affect the quality of the quantized image. Dithering creates an illusion of more color and more detail by mixing available colors. Factors such as original image quality, dithering algorithm used, dithering percentage, and color palette can all affect the resulting dithered image's quality.

Guidelines for selecting Dithering Algorithms

DynamicPDF Rasterizer supports the Floyd-Steinberg algorithm and Bayer dithering algorithms.

Floyd-Steinberg Algorithm

The Floyd-Steinberg algorithm is a high-quality error-diffusion method. It is the default dithering algorithm DynamicPDF Rasterizer uses during indexed image creation. Use this method for creating both monochrome images and color images. The Floyd-Steinberg algorithm produces higher-quality photos than the Bayer algorithm. Still, the trade-off is that creating images using the Floyd-Steinberg algorithm is slower than using the Bayer algorithm.

Bayer algorithm

The Bayer algorithm is an ordered dithering algorithm. The Bayer algorithm can be used to create monochrome and color images. Although image quality is lower when using the Bayer algorithm, the algorithm creates images faster than Floyd-Steinberg.

Guidelines for selecting Dithering Percentage

DynamicPDF Rasterizer supports setting a dithering percentage for an image to be selected from zero to 100. The dithering percentage specifies the percentage of pixels that will undergo dithering. Zero percent dithering results in no dithered pixels, and the resulting image may contain bands and patches. You avoid this poor image quality by setting the dithering to an appropriate value. For dithering percentages greater than zero, the higher the percentage, the greater the illusion of more color and more detail. However, as the image quality improves, so does the file size. If a small file size is of greater importance than image quality, select a lower dithering percentage. Images with primarily solid colors (PDF e-book pages converted to images) often work well with a lower dithering percentage. In contrast, images with gradients and containing more colors often require a higher dithering percentage to prevent color banding. Some experimentation with the optimal dithering percentage is often needed.

The following example illustrates rasterizing a PDF document into an indexed PNG using the Floyd-Steinberg dithering algorithm at a dithering percentage of 100%. It uses the AutoPalette, PngIndexedColorFormat, and PngImageFormat classes.

PdfRasterizer rasterizer = new PdfRasterizer(pdfFilePath);
AutoPalette autoPalette = new AutoPalette(QuantizationAlgorithm.Octree, 256);
PngIndexedColorFormat pngIndexedColorFormat = new PngIndexedColorFormat(autoPalette, 100, DitheringAlgorithm.FloydSteinberg);
PngImageFormat png = new PngImageFormat(pngIndexedColorFormat);
rasterizer.Draw(pngFilePath, png, ImageSize.Dpi72);        
Dim rasterizer As New PdfRasterizer(pdfFilePath)
Dim autoPalette As New AutoPalette(QuantizationAlgorithm.Octree, 256)
Dim pngIndexedColorFormat As New PngIndexedColorFormat(autoPalette, 100, DitheringAlgorithm.FloydSteinberg)
Dim png As New PngImageFormat(pngIndexedColorFormat)
rasterizer.Draw(pngFilePath, png, ImageSize.Dpi72)

In this topic