ImageQuality
This article explains how to use the ImageQuality enumeration to change the export of images in RadPdfProcessing and how it reflects the images in different scenarios.
Overview
The ImageQuality enumeration allows you to control the quality of the images when exporting to PDF. Possible values for this property are High, Medium, and Low. Since Q1 2016, the default value of ImageQuality is High.
Using ImageQuality
The quality of the images reflects the size of the PDF document. The higher the quality, the bigger the document size. This property can be set both in PdfExportSettings and in the constructor of ImageSource.
You can download a runnable project, which demonstrates different approaches for working with images in RadPdfProcessing from our SDK repository.
Set a Default Value for all Images in a Document
In order to specify the default ImageQuality value when exporting to PDF, you should use the PdfExportSettings.
Example 1: Set a default value for all images in a document
PdfExportSettings settings = new PdfExportSettings();
settings.ImageQuality = ImageQuality.Medium;
PdfExportSettings.ImageQuality
property doesn't affect the quality of the images imported from a PDF document. Such images are preserved usingEncodedImageData
(see ImageQuality and EncodedImageData Class).PdfExportSettings.ImageQuality
only affects the export quality of images created using an image stream or aBitmapSource
.
Specify the Image Quality of an Image
If you need some particular image to be exported with a different ImageQuality value, you should specify this value in the constructor of ImageSource in order to override the default one.
Example 2: Set the image quality of an image
ImageSource imageSource = new ImageSource(bitmap, ImageQuality.Medium);
ImageQuality and EncodedImageData Class
When you construct an ImageSource object with EncodedImageData, the image is inserted in the PDF file as it is, without decoding and re-encoding the image data. As RadPdfProcessing does not process the image data in this case, the PdfExportSettings.ImageQuality property is not used for this specific image and setting a value won’t take effect.
ImageQuality.High With JPEG and JPEG2000 Images
When ImageQuality of an image is set to High, RadPdfProcessing internally checks the image stream before processing it. If the image is JPEG or JPEG2000, it is inserted in the PDF file as it is, without processing the image pixels. This way, RadPdfProcessing provides fast and lossless quality export of JPEG and JPEG2000 files, which guarantees maximum quality in the exported document.
JPEG2000 images in RadPdfProcessing can be inserted only with ImageQuality.High. Exporting them with lower ImageQuality value requires decoding JPEG2000 files, which is currently unsupported by the library.
ImageQuality in .NET Standard
.NET Standard specification does not define APIs for converting images or scaling their quality. That is why to allow the library to export images different than Jpeg and Jpeg2000 or ImageQuality different than High, you will need to provide an implementation of the JpegImageConverterBase abstract class. This implementation should be passed to the JpegImageConverter property of the of FixedExtensibilityManager. For more information check the Cross-Platform Support help article.