locked
Load SVG from PCL by CODE USING FFImageLoading RRS feed

  • Question

  • User294116 posted

    Hello,

    I'm using this package from nugget to display images in SVG :

    https://github.com/luberda-molinet/FFImageLoading/wiki

    I'm able to load images using xaml from PCL like this:

    //using xmlns:ffimageloadingsvg="clr-namespace:FFImageLoading.Svg.Forms;assembly=FFImageLoading.Svg.Forms">

    //my image from resources in PCL

    <ffimageloadingsvg:SvgCachedImage WidthRequest="75" HeightRequest="93" Source="resource://MyProject.Resources.MenuLogo.svg" Margin="0,0,0,50" />

    Also I'm able to load images by code from a URL like this:

                  map = new SvgCachedImage()
                         {
                             DownsampleToViewSize = true,
                             DownsampleWidth = Width,
                             RetryCount = 0,
                             RetryDelay = 250,
                          Source = SvgImageSource.FromUri(new Uri("https://a/simple/web/formaps/1/12_Mapa_Path.svg"))
                         };
    

    The problem happens when I try to load an image from PCL by code :

            var logo = new SvgCachedImage()
            {
                DownsampleToViewSize = true,
                DownsampleWidth = Width,
    
            };
    

    I have tried to use different sources but:

    Source = SvgImageSource.FromFile("MenuLogo.svg") // No errors but does not display anything 
    
    Source = Xamarin.Forms.ImageSource.FromResource("MenuLogo.svg")// Like if it was a normal loading but nothing is displayed
    
    Source = SvgImageSource.FromResource("MyProject.Resources.MenuLogo.svg") // Cannot implicitly convert type 'FFImageLoading.Work.ImageSource' to 'Xamarin.forms.ImageSource'
    

    I don´t know what I'm doing wrong, and I have not found any documentation to load PCL svg by code.

    Anyone with the same problem or somebody could help me ?

    Thankyou, sorry about my English :smiley:

    Wednesday, August 2, 2017 12:12 PM

Answers

  • User2773 posted

    I would suggest to use resource:// url format (it's more optimized). More here: https://github.com/luberda-molinet/FFImageLoading/wiki/Data-URL-&-Embedded-Resources-support-(including-base64)

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Saturday, September 2, 2017 4:10 PM

All replies

  • User2773 posted

    I would suggest to use resource:// url format (it's more optimized). More here: https://github.com/luberda-molinet/FFImageLoading/wiki/Data-URL-&-Embedded-Resources-support-(including-base64)

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Saturday, September 2, 2017 4:10 PM
  • User380835 posted

    This link is more stating to the point about SVG support by FFImageloading

    https://github.com/luberda-molinet/FFImageLoading/wiki/SVG-support

    From the above link, you can find how to use SVG in Xamarin using FFImageloading

    Saturday, February 2, 2019 9:09 AM