[Expand]General Information
[Collapse]WinForms Controls
  Prerequisites
 [Expand]What's Installed
 [Expand]Build an Application
 [Collapse]Controls and Libraries
  [Expand]Forms and User Controls
  [Expand]Messages, Notifications, and Dialogs
  [Expand]Editors and Simple Controls
  [Expand]Ribbon, Bars and Menu
  [Expand]Application UI Manager
  [Expand]Docking Library
  [Expand]Data Grid
  [Expand]Vertical Grid
  [Expand]Property Grid
  [Expand]Pivot Grid
  [Expand]Tree List
  [Expand]Chart Control
  [Expand]Diagrams
  [Expand]Gauges
  [Expand]Map Control
  [Expand]Scheduler
  [Expand]Spreadsheet
  [Collapse]Rich Text Editor
   [Expand]Product Information
    Product Class Structure
    Supported Formats
   [Expand]Getting Started
   [Collapse]RichEditControl Document
    [Expand]Document Structure
    [Collapse]Document Elements
      Positions and Ranges
      Paragraphs
      Sections
      Lists
      Inline Pictures
      Shapes
      Text Boxes
      Hyperlinks and Bookmarks
      Headers and Footers
      Tables
      Range Permissions
      Comments
      Checkboxes
      Document Properties
   [Expand]Fields
    Text Formatting
    Import and Export
   [Expand]Page Layout
    Printing
    Spell Checking
    AutoCorrect Feature
    Mail Merge
    Restrictions and Protection
    Syntax Highlighting
   [Expand]Visual Elements
    Services
    Events
    Commands
    Keyboard Shortcuts
    HTML Tag Support
   [Expand]Examples
  [Expand]Spell Checker
  [Expand]Form Layout Managers
  [Expand]Navigation Controls
  [Expand]Printing-Exporting
  [Expand]PDF Viewer
   Reporting
  [Expand]Snap
  [Expand]TreeMap Control
  [Expand]Sunburst Control
 [Expand]Common Features
  Get More Help
 [Expand]API Reference
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]ASP.NET Core Bootstrap Controls
[Expand]WPF Controls
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Office File API
[Expand]Reporting
[Expand]Report and Dashboard Server
[Expand]Dashboard
[Expand]eXpressApp Framework
[Expand]eXpress Persistent Objects
[Expand]CodeRush
[Expand]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation
View this topic on docs.devexpress.com (Learn more)

Inline Pictures

Note

Refer to the Shapes article for information on new pictures and shapes.

Expanded Pictures in the User Interface

End users can use the Insert ribbon tab to insert pictures in a document. Click Pictures button to invoke the browser dialog and select target image files.

When image is selected, the Picture Tools | Format contextual tab becomes available. This tab allows you to change the image's position, text wrapping, and outline options. The inline image has In line with Text wrapping style.

Note

If you you work with documents created in a Microsoft Word version earlier than 2007, its inline images do not have additional UI elements.

Right-click an image and select More Layout Options... to invoke the Shape Layout Dialog. This dialog allows end users to specify advanced drawing object's properties.

Expanded Pictures in Code

Create an Image

All images in the document are contained in two collections: DocumentImageCollection (accessible by the SubDocument.Images property) and ShapeCollection (see ShapeCollection) (accessible by the SubDocument.Shapes property).

Call the DocumentImageCollection.Append or DocumentImageCollection.Insert method to place an inline image in the document. The resulting object is also added to the ShapeCollection (see ShapeCollection).

Note

When you work with documents created in a Microsoft Word version earlier than 2007, its inline pictures are stored in the DocumentImageCollection only.

Resize an Image

The following properties allow you to resize an inline image:

API

Description

DocumentImage.ScaleX

Gets or sets the X-axis scale factor.

DocumentImage.ScaleY

Gets or sets the Y-axis scale factor.

DocumentImage.Size

Specifies the picture's size in current measurement units (specified by the Document.Unit property).

The following example examines all images in the document. If the width of an image exceeds 50 millimeters, the image is scaled proportionally to half its size.

Obtain Image Information

The DocumentImage.Image property enables you to get information on image size, resolution and color depth. The returned OfficeImage object can be used to get a native .NET System.Drawing.Image (the OfficeImage.NativeImage property) or to get image data in a different format (the OfficeImage.GetImageBytes method).

The code sample below retrieves all images in the document and saves them as separate files.

To save an image from the document to a file, use the ReadOnlyDocumentImageCollection.Get method to obtain a collection of images within the specified range, and use the OfficeImage.NativeImage property, which allows access to a native System.Drawing.Image object. This object has the Save method that accomplishes the task.

Tip

Use the ReadOnlyDocumentImageCollection.Get method to get images from the specified range (see Range).

Delete an Image

Clear the range occupied by the image to delete this image from the document. The DocumentImage.Range property returns the related range.

Export Specifics

RTF

Use the RtfDocumentExporterCompatibilityOptions.DuplicateObjectAsMetafile property to specify whether to save inline pictures in the native format and as metafiles.

HTML

Handle the RichEditControl.BeforeExport event and specify the HtmlDocumentExporterOptions.UriExportType and IExporterOptions.TargetUri properties to specify a location for storing images as external files.

Create custom IUriProvider interface implementation and specify it instead of the default URI provider in the SubDocument.GetHtmlText method to create custom css and image URIs.

Note

A complete sample project is available at How to save the document range in different formats repository on GitHub.

The Document.HtmlText method uses a special URI provider (the DataStringUriProvider), which converts an image to a base64-encoded representation with the "data:" prefix. If you use the Document.HtmlText method to obtain the HTML content, all images are embedded in the page.

Expanded See Also

Is this topic helpful?​​​​​​​