-
Notifications
You must be signed in to change notification settings - Fork 0
/
Form1.cs
55 lines (46 loc) · 1.79 KB
/
Form1.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 System;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Windows.Forms;
using DevExpress.Office.Services;
namespace RichIUriStreamProviderExample
{
public partial class Form1 : DevExpress.XtraEditors.XtraForm
{
private string basePath;
public Form1()
{
InitializeComponent();
basePath = Directory.GetCurrentDirectory() + @"\..\..\TestDocs\";
// Custom IUriStreamProvider registration
IUriStreamService uriStreamService = richEditControl1.GetService<IUriStreamService>();
uriStreamService.RegisterProvider(new CustomUriStreamProvider(basePath, "bmp"));
}
private void btnImportFile_Click(object sender, EventArgs e)
{
richEditControl1.LoadDocument(basePath + "test.html");
}
}
public class CustomUriStreamProvider : IUriStreamProvider
{
private string basePath;
private string imageExtension;
public string BasePath { get { return basePath; } set { basePath = value; } }
public string ImageExtension { get { return imageExtension; } set { imageExtension = value; } }
public CustomUriStreamProvider(string basePath, string imageExtenssion)
{
BasePath = basePath;
ImageExtension = imageExtenssion;
}
public Stream GetStream(string url)
{
string fileName = string.Format("{0}.{1}", url.Replace("cid:", string.Empty), ImageExtension);
MemoryStream memoryStream = new MemoryStream();
using (Image image = Image.FromFile(BasePath + fileName))
image.Save(memoryStream, ImageFormat.Bmp);
memoryStream.Seek(0, SeekOrigin.Begin);
return memoryStream;
}
}
}