Load embedded SVG into HTMLViewer

I’m almost too embarrassed to ask, but I’ve been going around in circles for 2 hours and the documentation is not helping, although that could be my fault.

I have an SVG image embedded in my Web App. (ie I dragged and dropped it into a Xojo folder which I’ve named “Images” - I am not loading it from an external folder at runtime)

I want to populate an instance of HTMLViewer with this image - ie pass the string data of the SVG into the HTMLViewer using .LoadHTML(). I suspect this is absurdly easy/obvious, but I can’t work out the correct way to access the file’s string data. Could somebody point me to the correct way?

When I construct the SVG string data manually, it all works as expected.

Thanks

It should just be referencing the SVG file by name since you dragged it in, right? I think SVGs reference like text files?

var sSVGXML as String = mySvgInTheNavigator
ctlHTML.LoadHTML(sSVGXML)

I’ve been quite enjoying that WebPicture.BootstrapIcon("name").Data provides the Bootstrap SVG. I haven’t needed to reference anything manually in Web 2.0 yet.

Have you tried anything that isn’t working?

2 Likes

Hi Tim, thanks for helping out.

I did try the above, but I got:

Type mismatch error. Expected String, but got class WebPicture

I guess Xojo is converting that to a WebPicture.

Add a Constant to your project, paste the SVG string data to it, use the LoadHTML(your_constant)

1 Like

Hi Alberto,
I’m currently just testing this with the one image, but there are potentially several hundred to deal with, so although adding them as constants would work, I’d ideally like to find a solution that does not involve me having to maintain these values.
But yes, failing all else, hard coded strings are what I’ll have to go with.

If you’re going to have several hundred of them, leave them as files in a folder in Resources and open them as needed and read them as a string.

2 Likes