This is a migrated thread and some comments may be shown as answers.

Replacing images from document

2 Answers 42 Views
RichTextEditor
This is a migrated thread and some comments may be shown as answers.
Dan
Top achievements
Rank 1
Dan asked on 22 Feb 2017, 06:50 PM

Hello,

I am looking for a way to find all the images from a document and run them through a compressing do reduce the document size.

I found a way to find all images and I have the code to compress them but I am not sure how to replace the image after I find them.

foreach (Section section in this.radRichTextEditor1.Document.Sections)
{
    foreach (Block block in section.Blocks)
    {
        Paragraph p = block as Paragraph;
        if (p != null)
        {
            foreach (Inline inlineElement in p.Inlines)
            {
                ImageInline image = inlineElement as ImageInline;
                if (image != null)
                {
                    Telerik.WinControls.RichTextEditor.UI.BitmapSource bitSource;
                    bitSource = image.ImageSource;
                }
            }
        }
    }
}

Regards, Dan

2 Answers, 1 is accepted

Sort by
0
Dan
Top achievements
Rank 1
answered on 23 Feb 2017, 01:57 PM

This is resolved. My first attempt was to remove and add the Inline object but it turns out that I can use the ImageInline.Init method to update the image.

Regards, Dan

0
Hristo
Telerik team
answered on 23 Feb 2017, 02:26 PM
Hello Dan,

Thank you for sharing your solution. Indeed that is the correct approach. The ImageInline.Init method will initialize a new raw image data out of the provided stream and set it as an image source of the element.

I hope this helps. Please let me know if you need further assistance.

Regards,
Hristo
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
RichTextEditor
Asked by
Dan
Top achievements
Rank 1
Answers by
Dan
Top achievements
Rank 1
Hristo
Telerik team
Share this question
or