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

Extract Image From RadEditor's Document

1 Answer 134 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
SHSIOW
Top achievements
Rank 1
SHSIOW asked on 27 Aug 2016, 05:04 PM

As per subject, I wonder if we can some how "extract" the image in our RadDocument.

The background - I wanted user to be able to manipulate their photo via WPF apps but once it is uploaded to my website, I need those content to be translated into images so that I can save those images and refer to it via URL.

1 Answer, 1 is accepted

Sort by
0
Boyko
Telerik team
answered on 31 Aug 2016, 10:57 AM
Hello SHSIOW,

As I understand from your question, you need to extract the images from a RadDocument instance, loaded in RadRichTextBox. Please correct me if I am wrong.

If this is the case, the following code extracts the images from the RadDocument and saves them to a specified location:   

List<ImageInline> images = radRichTextBox.Document.EnumerateChildrenOfType<ImageInline>().ToList();
 
string basePath = @"C:\SavedImages\{0}{1}{2}";
 
for (int i = 0; i < images.Count(); i++)
{
    ImageInline image = images[i];
    using (FileStream fs = File.Create(string.Format(basePath, i, ".", image.Extension)))
    {
        Stream imageStream = new MemoryStream(image.GetBytes());
        imageStream.Seek(0, SeekOrigin.Begin);
        imageStream.CopyTo(fs);
        imageStream.Close();
    }
}

Hope this helps.

Regards,
Boyko
Telerik by Progress
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
Tags
RichTextBox
Asked by
SHSIOW
Top achievements
Rank 1
Answers by
Boyko
Telerik team
Share this question
or