I need to be able to display an SVG or PNG image returned from an API call. SVG would be ideal but I understand Desktop does not support SVG. In any case, let’s assume I am dealing with a PNG, I need some help trying to display the image in the application to the end user.
I have a rough idea on what I need to do, but not sure how to execute this. Possible steps:
Just grab the data with URLConnection, create the picture using Picture.FromData, then set that picture to the ImageViewer.Image property.
var u as new URLConnection
var imageData as String = u.SendSync( "GET", "https://quickchart.io/graphviz?format=png&width=100&height=150&graph=graph%7Ba--b%7D" )
if u.HTTPStatusCode = 200 then
var p as Picture = Picture.FromData( imageData )
ImageViewer1.Image = p
end if
If you want to use an HTMLViewer for the SVG (not what I’d do in this scenario), you can just load the URL in the HTMLViewer.
It’s not that I wouldn’t use SVG, I just wouldn’t do it with an HTMLViewer. It’s a bit overkill and won’t give you an object you can manipulate as a native Xojo object unless you use the third-party resource suggested by Tim, which I understand is well worth it.
The Einhuger plugin failed to correctly render some SVGs we tested due to limitations in the underlying SVG library. The library which the MBS plugin uses handled these correctly.
Can’t remember if they were complex or not. They rendered okay in web browsers and resvg (which is what MBS uses) but didn’t renderer correctly by the Einhuger plugin (lunasvg).
Xojo could integrate with one of these libraries quite easily. I think it would be a bad idea for them to write their own SVG parser as it would take 100’s of man hours to get something decent.