In your example, located at https://github.com/telerik/xaml-sdk/blob/master/PdfProcessing/CreateDocumentWithImages/MainViewModel.cs , you go through how to encode a dual tone image. I have tried to apply this same logic to an 32 bit ARGB image, one directly from RadChartView.ExportToImage, but the image comes out in gray scale and not even in the correct dimensions. I am not sure what I am missing, I've even changed the color space from DeviceGray to DeviceRGB with no luck and set bits per component to 8. I am calculating stride and data correct array size correctly...
6 Answers, 1 is accepted
EncodedImageData class is intended to provide extensibility mechanism allowing users to create images from otherwise unsupported formats (such as JPEG2000 images with JPXDecode filter) or to maximize compression for dual tone black and white images with bits per component 1. However, in the standard scenario when you have ARGB image you should better use some of the other ImageSource constructors taking instance or image file Stream instance. If you additionally need to optimize the performance and memory consumption of your application you may use the corresponding constructors that take parameter as argument. This way PdfProcessing will create the needed PDF image at the time of ImageSource creation and no additional resources will be kept during the ImageSource instance life. Knowing this some of the following constructors may be used in the mentioned scenario:
I hope this is helpful.
Telerik by Progress
Thanks for the reply Deyan. The issue I am having is that the quality of the image is being degraded more than I would like once it is inserted into the pdf (the pdf export quality is set to high as well). The image itself is of much higher quality than what is ending up in the pdf. How can I insert an image without any loss in image quality? I thought the EncodedImageDataClass may be the way to go about it...
You are right that by inserting the image with EncodedImageData and FlateDecode compression you will export the image to the PDF file without any loss of quality. In the current version of the product EncodedImageData class allows you to create only images without any transparency. However, as it was relatively easy for implementation, we have decided to introduce some additional public API in this class that would allow you to export images with transparency as well. The DLL files with this new public API should be available for download next week with the latest internal build. You may follow this feedback item in order to be notified when its status is officially changed from "In Development" to "Completed" and see when exactly you will be available to download the implementation. You should additionally know that the implementation is developed by the WPF team and will be available for download from the WPF download section in you clients profile. If you are not developing a WPF application you should not worry as RadPdfProcessing is UI independent library and its DLL files are same for all platforms.
I am attaching a demo application showing how to export RGBA image without any loss of quality with EncodedImageData class. The demo app uses EncodedImageData constructor taking alphaChannel as an argument and this constructor will be available with the newly introduced functionality. If you want to test the demo now without the new functionally you may simply delete the alpha variable from the EncodedImageData constructor. This way you will successfully export the image to the PDF file by losing the transparency.
I hope this is helpful. If you have any other questions or concerns please do not hesitate to contact us again.
Telerik by Progress
Thank you Deyan. It worked beautifully.
thank you for providing the example solution, however we have a problem with some images using your method, see attached.
our use case is that we use the Telerik WPF diagrams to generate a lot of images and then slice it to insert hyperlinks inside the PDF, so a lot of pixels with simple colors, even the ImageQuality.Low setting will create a larger PDF file than with the FlatDecode method, of course the quality then is unacceptable, so we really like to use the FlatDecode method.
When opening the PDF it will throw an error "An error exists on this page".
When opening the PDF it will throw an error "Insufficent data for an image"
I could fix this error by adding some additional bytes to the array, aligning it to 4, why is that?
Thank you for the feedback.
The provided images are not sufficient in order to investigate the described behavior. Could I ask you to send us the documents causing it so we can investigate them deeper? You can do that by opening a new support ticket and attach them. I must assure you we treat all client files in a strictly confidential manner and for testing purposes only.
Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.