/
InlinePicturesActions.vb
57 lines (54 loc) · 2.52 KB
/
InlinePicturesActions.vb
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
56
57
Imports DevExpress.XtraRichEdit.API.Native
Imports System
Imports System.Collections.Generic
Imports System.IO
Imports System.Linq
Imports System.Text
Imports System.Threading.Tasks
Imports System.Windows
Imports System.Windows.Resources
Namespace DXRichEditControlAPISample.CodeExamples
Friend Class InlinePicturesActions
Private Shared Sub ImageFromFile(ByVal document As Document)
' #Region "#ImageFromFile"
Dim pos As DocumentPosition = document.Range.Start
Dim streamResInfo As StreamResourceInfo = Application.GetResourceStream(New Uri("beverages.png", UriKind.Relative))
If streamResInfo IsNot Nothing Then
Using s As Stream = streamResInfo.Stream
document.Images.Insert(pos, DocumentImageSource.FromStream(s))
End Using
End If
' #End Region ' #ImageFromFile
End Sub
Private Shared Sub ImageCollection(ByVal document As Document)
' #Region "#ImageCollection"
document.LoadDocument("Documents//Grimm.docx", DevExpress.XtraRichEdit.DocumentFormat.OpenXml)
Dim images As ReadOnlyDocumentImageCollection = document.Images
' If the width of an image exceeds 50 millimeters,
' the image is scaled proportionally to half its size.
For i As Integer = 0 To images.Count - 1
If images(i).Size.Width > DevExpress.Office.Utils.Units.MillimetersToDocumentsF(50) Then
'INSTANT VB WARNING: Instant VB cannot determine whether both operands of this division are integer types - if they are then you should use the VB integer division operator:
images(i).ScaleX /= 2
'INSTANT VB WARNING: Instant VB cannot determine whether both operands of this division are integer types - if they are then you should use the VB integer division operator:
images(i).ScaleY /= 2
End If
Next i
' #End Region ' #ImageCollection
End Sub
Private Shared Sub SaveImageToFile(ByVal document As Document)
' #Region "#SaveImageToFile"
document.LoadDocument("Documents//MovieRentals.docx", DevExpress.XtraRichEdit.DocumentFormat.OpenXml)
Dim myRange As DocumentRange = document.CreateRange(0,100)
Dim images As ReadOnlyDocumentImageCollection = document.Images.Get(myRange)
If images.Count > 0 Then
Dim myImage As DevExpress.Office.Utils.OfficeImage = images(0).Image
Dim image As System.Drawing.Image = myImage.NativeImage
Dim imageName As String = String.Format("Image_at_pos_{0}.png", images(0).Range.Start.ToInt())
image.Save(imageName)
System.Diagnostics.Process.Start("explorer.exe", "/select," & imageName)
End If
' #End Region ' #SaveImageToFile
End Sub
End Class
End Namespace