This project is read-only.

How to load PNG as `byte[]` to HtmlImageLoadEventArgs callback?

Feb 16, 2015 at 3:32 PM
Edited Feb 19, 2015 at 11:28 AM
I have a PNG from a database as byte[]. How can I set as a HTML image? I use this for PDF creation and the wiki/documentation is sadly lacking...
public void HandleImageLoad(object sender, HtmlImageLoadEventArgs args)
      var img = LoadFromSource();
        if(img == null)
            args.Handled = false;
            Log.Error("Missing image: {0}", args.Src);
            args.Handled = true;
Feb 19, 2015 at 11:27 AM
Edited Feb 19, 2015 at 11:27 AM
For future reference:
The trick is to create a GDI image from a MemoryStream of the PNG picture. That can then be used to create a XImage as callback parameter.
using(var mem = new MemoryStream(img.Data))
    System.Drawing.Image sysImg = System.Drawing.Image.FromStream(mem, false, true);
    XImage ximg = XImage.FromGdiPlusImage(sysImg);