Print Image shown in RadImageEditor

1 Answer 190 Views
ImageEditor
Julien
Top achievements
Rank 1
Julien asked on 12 Apr 2022, 09:10 AM

Hello,

We are planning to use the WPf RadImage in order to preview, maybe retouch, save and print images.

Then I have two questions :

Can we import base64 string images in RadImageEditor ?

Is there a way to print from the RadImageEditor ?

Thanks for your help

Julien

1 Answer, 1 is accepted

Sort by
0
Dilyan Traykov
Telerik team
answered on 15 Apr 2022, 08:26 AM

Hello Julien,

Indeed, you can import a base64 string as an image to the RadImageEditor control in a similar manner:

            byte[] binaryData = Convert.FromBase64String(base64string);
            imageEditorUI.Image = new Telerik.Windows.Media.Imaging.RadBitmap(new MemoryStream(binaryData));

As for the printing, currently, the RadImageEditor control does not provide an API for printing its images, but we do have an open feature request for which you can vote: ImageEditor: Add printing support.

With that said, you could still achieve the desired result, for example, by subscribing to the Click event of a button. In it, you could create a new PrintDialog class, as well as utilize the RadBitmap class, to prepare the image for printing, and finally, call the PrintVisual method of the created print dialog instance. The following code snippet shows this approach implemented:

        private void RadButton_Click(object sender, RoutedEventArgs e)
        {
            PrintDialog dialog = new PrintDialog();
            if (dialog.ShowDialog() == true)
            {
                var imageEditor = this.ImageEditorUI.ImageEditor;
                RadBitmap radBitmap = imageEditor.Image;

                if (imageEditor.Image.Width > dialog.PrintableAreaWidth || imageEditor.Image.Height > dialog.PrintableAreaHeight)
                {
                    //the image needs to be scaled
                    double scaleX = dialog.PrintableAreaWidth / (double)imageEditor.Image.Width;
                    double scaleY = dialog.PrintableAreaHeight / (double)imageEditor.Image.Height;
                    double scale = Math.Min(scaleX, scaleY);

                    radBitmap = radBitmap.Resize((int)(radBitmap.Width * scale), (int)(radBitmap.Height * scale));
                }

                Image image = new Image();
                image.Source = radBitmap.Bitmap;
                dialog.PrintVisual(image, "RadImageEditor");
            }
        }

I hope you find this information helpful.

Regards,
Dilyan Traykov
Progress Telerik

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/.

Tags
ImageEditor
Asked by
Julien
Top achievements
Rank 1
Answers by
Dilyan Traykov
Telerik team
Share this question
or