DocumentImageSource.FromFile(String) Method
Creates an image source object from the specified file.
Namespace: DevExpress.XtraRichEdit.API.Native
Assembly: DevExpress.RichEdit.v24.1.Core.dll
NuGet Packages: DevExpress.RichEdit.Core, DevExpress.Win.Navigation
Declaration
Parameters
Name | Type | Description |
---|---|---|
fileName | String | A string that contains the name of the file from which to create the image. |
Returns
Type | Description |
---|---|
DocumentImageSource | A DocumentImageSource object representing the image in the document. |
Remarks
The following code sample demonstrates how the FromFile
method can be used to insert an image:
using DevExpress.BarCodes;
using DevExpress.XtraRichEdit;
using DevExpress.XtraRichEdit.API.Native;
using (var wordProcessor = new RichEditDocumentServer()) {
wordProcessor.LoadDocument("Texts\\Pictures.docx");
Document doc = wordProcessor.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.Shapes.InsertPicture(pos, DocumentImageSource.FromFile("Pictures\\ReadersChoice.png"));
}
Note
When you use theFromFile
method to create an image, the method locks the file until the application is closed. This happens because the method internally creates a file stream intended to load the image from the file, which is not disposed of together with the RichEditDocumentServer/RichEditControl instance and stays alive until you close the application.
If you require releasing the file while the program is running, you can use the DocumentImageSource.FromStream method to create an image and close the stream manually after the image is inserted into the document.
Related GitHub Examples
The following code snippets (auto-collected from DevExpress Examples) contain references to the FromFile(String) 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.