-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathImageStreamProvider.cs
39 lines (33 loc) · 1.12 KB
/
ImageStreamProvider.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
using System.IO;
using System.Data;
using DevExpress.Office.Services;
namespace RichEditImageMailMerge {
#region #iuristreamprovider
public class ImageStreamProvider : IUriStreamProvider {
static readonly string prefix = "dbimg://";
DataTable table;
string columnName;
public ImageStreamProvider(DataTable sourceTable, string imageColumn) {
this.table = sourceTable;
this.columnName = imageColumn;
}
public Stream GetStream(string uri) {
uri = uri.Trim();
if (!uri.StartsWith(prefix))
return null;
string strId = uri.Substring(prefix.Length).Trim();
int id;
if (!int.TryParse(strId, out id))
return null;
DataRow row = table.Rows.Find(id);
if (row == null)
return null;
byte[] bytes = row[columnName] as byte[];
if (bytes == null)
return null;
MemoryStream memoryStream = new MemoryStream(bytes);
return memoryStream;
}
#endregion #iuristreamprovider
}
}