Search code examples
xamarin.androiduwp-xamlxamarin.uwpffimageloading

Xamarin FFImageLoading Usage Clarification


I see we use FFImageLoading like below

var cachedImage = new CachedImage() {
    HorizontalOptions = LayoutOptions.Center,
    VerticalOptions = LayoutOptions.Center,
    WidthRequest = 300,
    HeightRequest = 300,
  ...
    Source = <url or asset or resource location>

};

or in XAML:

<ffimageloading:CachedImage 
  HorizontalOptions="Center" VerticalOptions="Center"
    WidthRequest="300" HeightRequest="300"
    DownsampleToViewSize="true"
    Source = "<url or asset or resource location>>
</ffimageloading:CachedImage>

, so, I replaced all instances of Image in my UWP project and ImageView in my Android project with CachedImage.

But after reading through FFImageLoading documentation, I also see lots of cases where images are loaded using ImageService. For example:

ImageService.Instance.LoadUrl(urlToImage).Into(_imageView);
ImageService.Instance.LoadCompiledResource(nameOfResource).Into(_imageView);
...
  • What is the difference between these two ways?

  • Why would I use one over the other?


Solution

  • FFImageLoading is a multi-platform library. ImageService.Instance methods are used to load images into native views (like ImageViewAsync on Android or UIImageView on iOS) and also for some advanced scenarios. There are also platform specific controls which internally use those methods, like:

    • CachedImage for Xamarin.Forms
    • MvxCachedImageView for native Android/iOS/Windows or MVVM Cross

    They allow you for using things like bindings out of the box.

    I advice you to use platform specific controls and use ImageService.Instance calls for advanced things. But it's entirely up to you.