Skip to main content

DocumentImageSource.FromUri(String, IServiceContainer) Method

SECURITY NOTE

Downloading images passed as URLs to the FromUri method may create security issues. Review the following help topic and learn how to spot, analyze, and prohibit unwanted download requests:

Suppress Control Requests to Download Data from External URLs

Creates an image source object from the specified URI string.

Namespace: DevExpress.XtraRichEdit.API.Native

Assembly: DevExpress.RichEdit.v23.2.Core.dll

NuGet Packages: DevExpress.RichEdit.Core, DevExpress.Win.Navigation

Declaration

[ComVisible(false)]
public static DocumentImageSource FromUri(
    string uri,
    IServiceContainer serviceContainer
)

Parameters

Name Type Description
uri String

A string of characters identifying the resource in the Internet that can be interpreted as an image.

serviceContainer IServiceContainer

An object providing the IUriStreamService interface which allows you to get a data stream for a specified URI.

Returns

Type Description
DocumentImageSource

A DocumentImageSource object representing the image in the document.

Remarks

Use the RichEditControl instance as the service container, to get images for the specified URI or implement your own service provider. The following example demonstrates how the FromUri method can be used to load an image by its URL.

This example illustrates how to insert inline pictures in a rich text document. The image can be obtained from a file, from a stream or from a URI.

View Example

using System.IO;
using System.Reflection;
using DevExpress.XtraRichEdit;
using DevExpress.XtraRichEdit.API.Native;
RichEditDocumentServer server = new RichEditDocumentServer();

server.LoadDocument("Texts\\InlinePictures.rtf", DocumentFormat.Rtf);
Document doc = server.Document;

// Insert an image from a file.
DocumentRange rangeFound = doc.FindAll("Visual Studio Magazine", SearchOptions.CaseSensitive)[0];
DocumentPosition pos = doc.Paragraphs[doc.Paragraphs.Get(rangeFound.End).Index + 2].Range.Start;
doc.Images.Insert(pos, DocumentImageSource.FromFile("Pictures\\ReadersChoice.png"));

// Insert an image from a stream.
pos = doc.Paragraphs[4].Range.Start;
string imageToInsert = "information.png";
Assembly a = Assembly.GetExecutingAssembly();
Stream imageStream = a.GetManifestResourceStream("InlinePictures.Resources." + imageToInsert);
doc.Images.Insert(pos, DocumentImageSource.FromStream(imageStream));

// Insert an image using its URI.
string imageUri = "http://i.gyazo.com/798a2ed48a3535c6c8add0ea7a4fc4e6.png";
SubDocument docHeader = doc.Sections[0].BeginUpdateHeader();
docHeader.Images.Append(DocumentImageSource.FromUri(imageUri, server));
doc.Sections[0].EndUpdateHeader(docHeader);


// Insert a barcode.
DevExpress.BarCodes.BarCode barCode = new DevExpress.BarCodes.BarCode();
barCode.Symbology = DevExpress.BarCodes.Symbology.QRCode;
barCode.CodeText = "https://www.devexpress.com/";
barCode.CodeBinaryData = System.Text.Encoding.Default.GetBytes(barCode.CodeText);
barCode.Module = 0.5;
SubDocument docFooter = doc.Sections[0].BeginUpdateFooter();
docFooter.Images.Append(barCode.BarCodeImage);
doc.Sections[0].EndUpdateFooter(docFooter);

The following code snippets (auto-collected from DevExpress Examples) contain references to the FromUri(String, IServiceContainer) method.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

See Also