Data URI scheme for embedded image support
I'm converting some app report generation and display code from the Xul/Skybound.Gecko (Firefox) library to HTMLUi.
The XUL code used embedded images via the 'data:' Uri. It would be very nice if HTMLUi could support this in future versions; or if it already supports this, is something I need to do differently?
Thank you!
---
Here are the details I was able to find on the 'data:' method:
http://en.wikipedia.org/wiki/Data_URI_scheme
Working
tags look like:

Our C# code build or loaded an image and embedded that in the html report with the extension method:
public static string EmbeddedHtml(this Image image)
{
string Template = @"
";
MemoryStream stream = new MemoryStream();
image.Save(stream, ImageFormat.Png);
stream.Flush();
return string.Format(Template, Convert.ToBase64String(stream.GetBuffer()));
}
The XUL code used embedded images via the 'data:' Uri. It would be very nice if HTMLUi could support this in future versions; or if it already supports this, is something I need to do differently?
Thank you!
---
Here are the details I was able to find on the 'data:' method:
http://en.wikipedia.org/wiki/Data_URI_scheme
Working
Our C# code build or loaded an image and embedded that in the html report with the extension method:
public static string EmbeddedHtml(this Image image)
{
string Template = @"
MemoryStream stream = new MemoryStream();
image.Save(stream, ImageFormat.Png);
stream.Flush();
return string.Format(Template, Convert.ToBase64String(stream.GetBuffer()));
}
SIGN IN To post a reply.
3 Replies
JM
Joel McIntyre
September 30, 2010 06:46 PM UTC
And I was able to roll my own embedded image conversion with some tweaking. I had to change embedded format above from "data:..., " to "data|" (substituting the colon and dropping the encodings), and then hooking PreRenderDocument and iterating through all images like the abbreviated error-checking-absent code below.
If there is an easier, more supported method, or more standardized method, please do let me know! And if you accept the "data:" feature, I am still interested - better a portable format.
Hope this helps the rest of y'all! Cheers.
---
void control_PreRenderDocument(object sender, PreRenderDocumentArgs e)
{
LoadInlineImages(e.Document);
}
void LoadInlineImages(InputHTML Document)
{
Hashtable elements = Document.ElementsByTagName;
if (elements != null)
{
ArrayList imagelist = elements["img"] as ArrayList;
if (imagelist != null)
{
foreach (IMGElementImpl image in imagelist.OfType())
{
Bitmap graphic = GetImageByName(image.Attributes["src"].Value);
if (graphic != null)
{
image.Image = graphic;
}
}
}
}
}
Bitmap LoadDataImage(string Name)
{
string Base64 = Name.Substring(Name.IndexOf("|") + 1).TrimStart();
byte[] Data = Convert.FromBase64String(Base64);
return Image.FromStream(new MemoryStream(Data)) as Bitmap;
}
If there is an easier, more supported method, or more standardized method, please do let me know! And if you accept the "data:" feature, I am still interested - better a portable format.
Hope this helps the rest of y'all! Cheers.
---
void control_PreRenderDocument(object sender, PreRenderDocumentArgs e)
{
LoadInlineImages(e.Document);
}
void LoadInlineImages(InputHTML Document)
{
Hashtable elements = Document.ElementsByTagName;
if (elements != null)
{
ArrayList imagelist = elements["img"] as ArrayList;
if (imagelist != null)
{
foreach (IMGElementImpl image in imagelist.OfType
{
Bitmap graphic = GetImageByName(image.Attributes["src"].Value);
if (graphic != null)
{
image.Image = graphic;
}
}
}
}
}
Bitmap LoadDataImage(string Name)
{
string Base64 = Name.Substring(Name.IndexOf("|") + 1).TrimStart();
byte[] Data = Convert.FromBase64String(Base64);
return Image.FromStream(new MemoryStream(Data)) as Bitmap;
}
JM
Joel McIntyre
September 30, 2010 06:54 PM UTC
// Missed a layer:
Bitmap GetImageByName(Name)
{
if (Name.StartsWith("data|")
return LoadDataImage(Name);
else
return null; // or do other types of image loads
}
Bitmap GetImageByName(Name)
{
if (Name.StartsWith("data|")
return LoadDataImage(Name);
else
return null; // or do other types of image loads
}
VS
Vallarasu S
Syncfusion Team
October 7, 2010 03:51 AM UTC
Hi Joel,
Thanks for your interest in Syncfusion products,
We regret to say that we don’t have plans to implement this as a feature in HTMLUI, You can continue using the PreRenderDocument event for such requirements.
Please let us know if you have concerns on this.
Regards
Vallarasu S.
Thanks for your interest in Syncfusion products,
We regret to say that we don’t have plans to implement this as a feature in HTMLUI, You can continue using the PreRenderDocument event for such requirements.
Please let us know if you have concerns on this.
Regards
Vallarasu S.
SIGN IN To post a reply.
- 3 Replies
- 2 Participants
-
JM Joel McIntyre
- Sep 30, 2010 04:29 PM UTC
- Oct 7, 2010 03:51 AM UTC