We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Data URI scheme for embedded image support

Thread ID:





96721 Sep 30,2010 04:29 PM UTC Oct 7,2010 03:51 AM UTC Windows Forms 3
Tags: HTMLUIControl
Joel McIntyre
Asked On September 30, 2010 04:29 PM UTC

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:


Working tags look like:

Red dot

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);
return string.Format(Template, Convert.ToBase64String(stream.GetBuffer()));

Joel McIntyre
Replied On 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)

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;

Joel McIntyre
Replied On September 30, 2010 06:54 PM UTC

// Missed a layer:

Bitmap GetImageByName(Name)
if (Name.StartsWith("data|")
return LoadDataImage(Name);
return null; // or do other types of image loads

Vallarasu S [Syncfusion]
Replied On 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.

Vallarasu S.


This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon