DocumentImageSource.FromFile(String) Method
Creates an image source object from the specified file.
Namespace: DevExpress.XtraRichEdit.API.Native
Assembly: DevExpress.RichEdit.v24.2.Core.dll
NuGet Package: DevExpress.RichEdit.Core
#Declaration
[ComVisible(false)]
public static DocumentImageSource FromFile(
string fileName
)
#Parameters
Name | Type | Description |
---|---|---|
file |
String | A string that contains the name of the file from which to create the image. |
#Returns
Type | Description |
---|---|
Document |
A 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 theFrom
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 Rich
If you require releasing the file while the program is running, you can use 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.