-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGINtaskpane.cs
85 lines (66 loc) · 2.61 KB
/
GINtaskpane.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
using System;
using System.Data;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Windows.Forms;
namespace GINtool
{
public partial class GINtaskpane : UserControl
{
public delegate void UpdateButtonStatus(bool visible);
public UpdateButtonStatus updateButtonStatus = null;
public GINtaskpane()
{
InitializeComponent();
HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
string html = ReadResource("GINtool.Resources.user_manual.htm");
doc.LoadHtml(html);
// parse document for images and return the src value
var urls = doc.DocumentNode.Descendants("img")
.Select(e => e.GetAttributeValue("src", null))
.Where(s => !String.IsNullOrEmpty(s));
// for each src entry found, read it from resources and display it as inline base64 encoded text
foreach (string _s in urls)
{
var assembly = Assembly.GetExecutingAssembly();
string _orig = string.Format("GINtool.Resources.{0}", _s);
Bitmap image = new Bitmap(assembly.GetManifestResourceStream(_orig));
string img = Base64Encoded(image);
string _nwe = string.Format("src='data:image/jpeg;base64, {0}'", img);
string rep = string.Format("src=\"{0}\"", _s);
html = html.Replace(rep, _nwe);
}
// show text in webbrowser component
webBrowser1.DocumentText = html;
}
public string ReadResource(string resourceName)
{
// Determine path
var assembly = Assembly.GetExecutingAssembly();
using (Stream stream = assembly.GetManifestResourceStream(resourceName))
{
if (stream != null)
using (StreamReader reader = new StreamReader(stream))
{
string result = reader.ReadToEnd();
return result;
}
}
return "";
}
public static String Base64Encoded(Image image)
{
using (MemoryStream m = new MemoryStream())
{
image.Save(m, ImageFormat.Jpeg);
byte[] imageBytes = m.ToArray();
// Convert byte[] to Base64 String
string base64String = Convert.ToBase64String(imageBytes);
return base64String;
}
}
}
}