Skip to main content

DocumentImageSource.FromStream(Stream) Method

Creates an image source object from the specified data stream.

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 FromStream(
    Stream stream
)

Parameters

Name Type Description
stream Stream

A Stream containing image data.

Returns

Type Description
DocumentImageSource

A DocumentImageSource object representing the image in the document.

Remarks

The following code sample illustrates how the FromStream can be used to insert an image at the cursor position from the data stream.

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 FromStream(Stream) 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