1

I am trying to use FFImageLoading like this:

AppDelegate:

CachedImageRenderer.Init();
CachedImageRenderer.InitImageSourceHandler();
var config = new FFImageLoading.Config.Configuration()
{
    VerboseLogging = true,
    VerbosePerformanceLogging = false,
    VerboseMemoryCacheLogging = false,
    VerboseLoadingCancelledLogging = false
};
ImageService.Instance.Initialize(config);
var ignore = typeof(FFImageLoading.Svg.Forms.SvgCachedImage);

Preloading:

    public void PreloadImages()
    {
        try
            var resources = Assembly.GetExecutingAssembly().GetManifestResourceNames();
            foreach (var r in resources)
            {
                if (!r.EndsWith(".svg")) continue;
                try
                {
                    var assemblyName = Application.Current?.GetType()?.GetTypeAssemblyFullName();
                    ImageService.Instance.LoadEmbeddedResource($"resource://{r}?assembly={Uri.EscapeUriString(assemblyName)}")
                    //ImageService.Instance.LoadEmbeddedResource($"resource://{r}?assembly={Assembly.GetExecutingAssembly().GetName().Name}")
                    .Success((info, result) =>
                    {
                        Debug.WriteLine($"Preloading success! Key: {info.CacheKey}");
                    })
                    .Preload();
                }
                catch (Exception ex)
                {
                    Debug.WriteLine($"LoaderPage.PreloadImages[{r}]", ex);
                }
            }
    }

When the code runs the images appear on the screens but my Application Output fills up with messages like this:

System.BadImageFormatException: Can't read image size properties. File corrupted?
  at FFImageLoading.Decoders.GifDecoder.SourceRegfToDecodedImageAsync (Foundation.NSData nsdata, CoreGraphics.CGSize destSize, System.nfloat destScale, FFImageLoading.Config.Configuration config, FFImageLoading.Work.TaskParameter parameters, FFImageLoading.Decoders.GifDecoder+RCTResizeMode resizeMode, FFImageLoading.Work.ImageInformation imageinformation, System.Boolean allowUpscale) [0x00068] in C:\projects\ffimageloading\source\FFImageLoading.Shared.IosMac\Decoders\GifDecoder.cs:62 
  at FFImageLoading.Decoders.GifDecoder.DecodeAsync (System.IO.Stream stream, System.String path, FFImageLoading.Work.ImageSource source, FFImageLoading.Work.ImageInformation imageInformation, FFImageLoading.Work.TaskParameter parameters) [0x000e4] in C:\projects\ffimageloading\source\FFImageLoading.Shared.IosMac\Decoders\GifDecoder.cs:45 
  at FFImageLoading.Work.ImageLoaderTask`3[TDecoderContainer,TImageContainer,TImageView].GenerateImageAsync (System.String path, FFImageLoading.Work.ImageSource source, System.IO.Stream imageData, FFImageLoading.Work.ImageInformation imageInformation, System.Boolean enableTransformations, System.Boolean isPlaceholder) [0x0007c] in C:\projects\ffimageloading\source\FFImageLoading.Common\Work\ImageLoaderTask.cs:337 
  at FFImageLoading.Work.ImageLoaderTask`3[TDecoderContainer,TImageContainer,TImageView].RunAsync () [0x0047c] in C:\projects\ffimageloading\source\FFImageLoading.Common\Work\ImageLoaderTask.cs:643
2021-02-24 01:50:30.338196+0900 Memorise.iOS[41119:898256] Image loading failed: resource://Memorise.Resources.Cards.pause_Light.svg?assembly=Memorise,%20Version=1.0.0.0,%20Culture=neutral,%20PublicKeyToken=null
System.BadImageFormatException: Can't read image size properties. File corrupted?

Note that some of the SVG are very simple ones and I have no idea why or how they are corrupt and also the do show on the screen.

Has anyone been able to get the preload working. Note that I tried two different ways to do LoadEmbeddedResource but neither worked.

Richard A
  • 191
  • 7
  • if your images are already stored locally as resources I'm not sure there is any benefit to using FF's caching mechanism – Jason Feb 23 '21 at 17:14
  • Okay, well that's a very good thing to know and thank you for that suggestion. I have so far I think spent many hours trying to get this to work correctly and had nothing but frustration. I might wait a while to see if anyone else has suggestions and if not then I will not use the caching. Have you had the chance to use SVGs with Xamarin yourself. If so, did you just do a normal load and not cache? – Richard A Feb 23 '21 at 17:26

0 Answers0