1


In my current Xamarin.Forms project I use FFImageLoader to render my SVGs. The Problem is that I would like to preload my images to avoid ugly "page building issues", but I don't understand how to realize it.

Current usage:

new SvgCachedImage {
    WidthRequest = 200,
    HeightRequest = 200,
    Source = new SvgImageSource(ImageSource.FromResource("Path.to.image.in.project.svg", 200, 200, true)
}

So what I want to do is loading the SvgImageSource into Cache and then "take" it from there, when needed.
Maybe I'm just to blind to find the solution in the documentation...

Thanks for your help!

jor
  • 25
  • 7
  • I am not sure about svg files but for pngs i use this ImageService.Instance.LoadCompiledResource("myimage.png").Preload(); – Emil Mar 22 '18 at 13:50
  • For embeded resource you should use LoadEmbeddedResource option but I havent tested if it works for svg files. let me know also if it works :) – Emil Mar 22 '18 at 13:52

1 Answers1

1
    ImageService.Instance.LoadEmbeddedResource("Path.to.image.in.project.svg")
                .WithCustomDataResolver(new SvgDataResolver(200, 200, true))
                .Preload();
Daniel Luberda
  • 7,374
  • 1
  • 32
  • 40
  • Thank you very much :) But how do I load them from there? – jor Mar 26 '18 at 09:29
  • Just use the same code you have in your initial post, cache will be used automatically. – Daniel Luberda Mar 26 '18 at 12:37
  • That's what I tried, but it doesn't seem to work... So on the first page I call what you suggested, but when I switch to the page, where the code I posted is used, it still takes the same time for the images to load. – jor Mar 26 '18 at 14:17
  • Please enable FFImageLoading verbose logging and see what the cache keys are (via custom config - it's on the wiki) – Daniel Luberda Mar 27 '18 at 09:19
  • Ok, so I activated logging and the problem seems to be that the preloading doesn't work: **"[0:] Generating/retrieving image: resource://Path.to.image.in.project.svg;(size=48x48,dip=True) [0:] Image loading failed: resource://Path.to.image.in.project.svg;(size=48x48,dip=True) System.IO.FileNotFoundException: resource://Path.to.image.in.project.svg"** But the svg definitely is there and marked as "Embedded Resource"... – jor Mar 27 '18 at 11:36
  • Your preload method is called from another assembly, you must provide it manually (LoadEmbeddedResource override). Library doesn't know which one you want to use so it uses a current one which is used first.. – Daniel Luberda Mar 29 '18 at 11:36
  • Ok, now I don't get the error anymore, but it still doesn't seem to work correctly: **[0:] Generating/retrieving image: resource://Path.to.image.in.project.svg?assembly=[Assembly],%20Version=1.0.0.0,%20Culture=neutral,%20PublicKeyToken=null;(size=213x213,dip=True)**. I think there should be a key instead? Like **[0:] Generating/retrieving image: 2280242F13A3BCBCCDF8F8324A384425;(size=213x213,dip=True)** – jor Apr 03 '18 at 10:43