1

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?

pixel
  • 9,653
  • 16
  • 82
  • 149

1 Answers1

2

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.

Daniel Luberda
  • 7,374
  • 1
  • 32
  • 40
  • If I understand correctly, ImageService.Instance is used only in code whereas CachedImage can be used in both code and XAML? – pixel Sep 26 '17 at 16:35
  • 2
    `ImageService` can be called in code, `CachedImage` can only be used in Xamarin.Forms (and it uses `ImageService` under the hood) – Daniel Luberda Sep 26 '17 at 17:50