Skip to main content
A newer version of this page is available. .

Inline Pictures

  • 2 minutes to read

RichEditControl allows inserting pictures into a document as inline images or floating objects.

Important

This document describes inline pictures. For information about floating pictures, refer to the Shapes article.

Overview

Inline Picture

An inline picture in a document is represented by the DocumentImage object. It occupies the range equivalent to one character, i.e., the DocumentRange.Length of the range is equal to 1.

The DocumentImage.Image property provides access to the previous level of image abstraction, and enables you to get information on image size, resolution and color depth. The OfficeImage object obtained via this property can be used to get a native .NET Image (the OfficeImage.NativeImage property) or to get image data in a different format (the OfficeImage.GetImageBytes method).

All images in the document are contained in the DocumentImageCollection accessible using the SubDocument.Images property. Use the DocumentImageCollection.Insert and DocumentImageCollection.Append methods to insert pictures into a document.

End-users can execute the InsertPictureCommand command. The corresponding button is located in the Insert Pages - Illustrations Ribbon page group. Change the picture’s Text Wrapping option (located on the Picture Tools contextual tab) to In line with text to convert a floating picture into inline.

RichEdit_Ribbon_Illustrations

Tip

The ReadOnlyDocumentImageCollection.Get method is designed to get images within the specified Range. To call the method, use the RichEditControl.Document.Images.Get notation.

Saving Pictures

When a document is saved as an 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 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 using the Document.HtmlText method, all images are embedded in a page.

See Also