-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathImageStreamProvider.vb
More file actions
38 lines (30 loc) · 1.27 KB
/
ImageStreamProvider.vb
File metadata and controls
38 lines (30 loc) · 1.27 KB
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
Imports System.IO
Imports System.Data
Imports DevExpress.Office.Services
Namespace RichEditImageMailMerge
'#Region "#iuristreamprovider"
Public Class ImageStreamProvider
Implements IUriStreamProvider
Private Shared ReadOnly prefix As String = "dbimg://"
Private table As DataTable
Private columnName As String
Public Sub New(ByVal sourceTable As DataTable, ByVal imageColumn As String)
table = sourceTable
columnName = imageColumn
End Sub
Public Function GetStream(ByVal uri As String) As Stream Implements IUriStreamProvider.GetStream
uri = uri.Trim()
If Not uri.StartsWith(prefix) Then Return Nothing
Dim strId As String = uri.Substring(prefix.Length).Trim()
Dim id As Integer
If Not Integer.TryParse(strId, id) Then Return Nothing
Dim row As DataRow = table.Rows.Find(id)
If row Is Nothing Then Return Nothing
Dim bytes As Byte() = TryCast(row(columnName), Byte())
If bytes Is Nothing Then Return Nothing
Dim memoryStream As MemoryStream = New MemoryStream(bytes)
Return memoryStream
End Function
'#End Region ' #iuristreamprovider
End Class
End Namespace