Replacing images from document

3 posts, 0 answers
  1. Dan
    Dan avatar
    16 posts
    Member since:
    Mar 2007

    Posted 22 Feb Link to this post

    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. Dan
    Dan avatar
    16 posts
    Member since:
    Mar 2007

    Posted 23 Feb in reply to Dan Link to this post

    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

  3. Hristo
    Admin
    Hristo avatar
    1028 posts

    Posted 23 Feb Link to this post

    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.
Back to Top