-
Notifications
You must be signed in to change notification settings - Fork 4
/
InlinePictures.cs
55 lines (52 loc) · 2.03 KB
/
InlinePictures.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
using DevExpress.XtraRichEdit.API.Native;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace RichEditAPISample.CodeExamples
{
class InlinePicturesActions
{
static void ImageFromFile(Document document)
{
#region #ImageFromFile
DocumentPosition pos = document.Range.Start;
document.Images.Insert(pos, DocumentImageSource.FromFile("beverages.png"));
#endregion #ImageFromFile
}
static void ImageCollection(Document document)
{
#region #ImageCollection
document.LoadDocument("Documents//Grimm.docx");
ReadOnlyDocumentImageCollection images = document.Images;
// If the width of an image exceeds 50 millimeters,
// the image is scaled proportionally to half its size.
for (int i = 0; i < images.Count; i++)
{
if (images[i].Size.Width > DevExpress.Office.Utils.Units.MillimetersToDocumentsF(50))
{
images[i].ScaleX /= 2;
images[i].ScaleY /= 2;
}
}
#endregion #ImageCollection
}
static void SaveImageToFile(Document document)
{
#region #SaveImageToFile
document.LoadDocument("Documents//MovieRentals.docx");
DocumentRange myRange = document.CreateRange(0,100);
ReadOnlyDocumentImageCollection images = document.Images.Get(myRange);
if (images.Count > 0)
{
DevExpress.Office.Utils.OfficeImage myImage = images[0].Image;
System.Drawing.Image image = myImage.NativeImage;
string imageName = String.Format("Image_at_pos_{0}.png", images[0].Range.Start.ToInt());
image.Save(imageName);
System.Diagnostics.Process.Start("explorer.exe", "/select," + imageName);
}
#endregion #SaveImageToFile
}
}
}