Search code examples
xamarin.androidffimageloading

In FFImageLoading how to load an image into memory in Xamarin Android?


Doing this, I believe that my images are only being cached on the disk:

ImageService.Instance.LoadUrl(item.profileImg)
.DownSample()
.BitmapOptimizations(true)
.LoadingPlaceholder("blank_profile_img.png", FFImageLoading.Work.ImageSource.CompiledResource)
.Into(holder.imgIcon);

Solution

  • As far as I know you can simply specify the cache type you'd like to use for that particular image, as it's stored against a key.

    So an example from one of the times where I use this library is something like:

    ImageService.Instance.LoadUrl(url)
                    .WithPriority(LoadingPriority.High)
                    .Retry(3, 200)
                    .LoadingPlaceholder("ProfilePlaceholder.png", ImageSource.CompiledResource)
                    .ErrorPlaceholder("ProfilePlaceholder.png", ImageSource.CompiledResource)
                    .WithCache(FFImageLoading.Cache.CacheType.All)
                    .Into(profileImage);
    

    The key part is:

    .WithCache(FFImageLoading.Cache.CacheType.All)
    

    You can specify either All, which means it will cache to IO and memory, or you can select it to just be IO, or just be memory.

    So yours would look something like:

    ImageService.Instance.LoadUrl(item.profileImg)
           .DownSample()
           .BitmapOptimizations(true)
           .LoadingPlaceholder("blank_profile_img.png", FFImageLoading.Work.ImageSource.CompiledResource)
           .WithCache(FFImageLoading.Cache.CacheType.Memory)
           .Into(holder.imgIcon);