maui
maui copied to clipboard
Load an SVG from web URL
Description
I would like to have the image control have the ability to load an SVG from a web URL. In Xamarin Forms I was able to do this with FFImageLoader, but this library doesn't support . net MAUI. I haven't seen an alternative for this.
Public API Changes
<Image Source="http://www.my.com/img.svg" />
Intended Use-Case
I want to be able load a list of records from my database dynamically which each links to an svg file hosted on my azure blob. I don't want to use pngs due to not being able to change it's color and worry about sizing. I don't want to embed in the app because then I cannot dynamically change the color of the image based on whether light theme or dark theme.
workaround might be downloading the svg and loading from MemoryStream from memory
We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.
Have you found any workaround for this? I've tried loading from file, but doesn't work.
I think what you're looking for is the ImageResourceConverter
as shown in this sample.
This has been built-in functionality since before this issue was created. I had no trouble finding it, maybe search engines have indexed it better since then?
EDIT: Ah, it's not built-in into MAUI, but into the CommunityToolkit. Personally, I see no reason not to use both, but that explains why some people might not have noticed. They might've thought it was a different library and did not apply to their situation.
@Ghostbird
The ImageResourceConverter you're talking about doesn't seem to have anything to do with the issue at hand here. The issue surrounds loading .svg files form a remote source. The ImageResourceConverter converts embedded image resource ID to its ImageSource.
I'm also looking for a way to load SVG files from a URL and haven't found one yet.
@GlacierFox Apologies, would the MediaSourceConverter
work for you? Maybe that's the one I was thinking of. I don't remember, it's been a while.
I made this: https://gist.github.com/andressbarajas/c2248d5925087f5b769aacb9af8f74a8
It doesnt load from a URL but it does load SVG data as a string ("<svg ..... ").
To load an SVG from a web URL, using SvgCachedImage
from https://www.nuget.org/packages/FFImageLoading.Maui works.
To use, reference FFImageLoading in xaml file using below.
xmlns:ffimageloading="clr-namespace:FFImageLoading.Maui;assembly=FFImageLoading.Maui"