Inline Objects (Pictures)
- 2 minutes to read
RichEditControl provides the means to insert pictures in a document and specify their characteristics. An image in a document is represented by the DocumentImage object. It occupies a range equivalent to one character, e.g. the DocumentRange.Length of the range is equal to 1.
To insert an image, you can execute the InsertPictureCommand or click the Insert Picture menu. XtraRichEdit API provides the SubDocument.InsertImage method that enables you to create inline images from different sources.
To obtain images located in a specified range, use the SubDocument.GetImages method.
When a document is saved as a RTF, inline pictures are saved two times:in the native format and as a metafile, both by default. Use the RtfDocumentExporterCompatibilityOptions.DuplicateObjectAsMetafile property to modify this behavior.
When a document is saved in an HTML format, you can specify a location for storing images as external files, or process them before saving. To accomplish this, handle the RichEditControl.BeforeExport event and specify the HtmlDocumentExporterOptions.UriExportType and IExporterOptions.TargetUri. Moreover, you can implement your own class with the IUriProvider interface and specify it, instead of the default URI provider in the SubDocument.GetHtmlText method.
The Document.HtmlText method uses a special URI provider - the DataStringUriProvider that converts an image to a base64-encoded representation with the "data:" prefix. Therefore, if you obtain the HTML of a document via the Document.HtmlText method, all images are embedded in a page.