SVG icons in Eto.Forms

Hey developers,

now, that R8 supports SVG icons, how can we add them to our panels using Eto?

The naïve approach of simply feeding an svg file to an Eto.Drawing.Bitmap fails miserably. Besides, the point is to keep the icon as vector, not rasterize it.

public static Bitmap Biodiversity = Bitmap.FromResource("EmbeddedResources.Icons_Biodiversity.svg");

Inner Exception 1:
NotSupportedException: No imaging component suitable to complete this operation was found.

Inner Exception 2:
COMException: The component cannot be found. (0x88982F50)

@CallumSykes, @curtisw can you help maybe?

Rhino.UI.ImageResources.CreateEtoIcon(string svgContents, int width, int height, bool adjustForDarkMode)

This would be your friend. Be careful as some of the CreateEtoIcon overloads take Resouce Ids and not SVG.

2 Likes

Thanks @CallumSykes!

I ended up using this overload:

public static Icon Test = Rhino.UI.ImageResources.CreateEtoIcon("EmbeddedResources.Icons_Biodiversity.svg", Assembly.GetExecutingAssembly(), 36, 36, false);

Any chance this can be backported to R7? I’d be happy to include external libraries if necessary to support vector icons in my plugins.

Hey @mrhe,

Sorry, no, we’re no longer making changes to Rhino 7 (unless we discover something catastrophic).

– Dale

Well, one could argue that some of the rasterized icons look catastrophically bad (see my tests below) but I fully understand your rationale.

image