Search code examples
androidxamarinffimageloading

FFImageLoading Load image from Mobile-Sdcard


I'm trying to load image from mobile. Same method with picasso is working fine but i get problem using FFImageloading

var CatalogCategories = System.IO.Path.Combine(Android.OS.Environment.GetExternalStoragePublicDirectory(Android.OS.Environment.DirectoryPictures).ToString(), "dbsoft");
ImageService.Instance.LoadFile(new Java.IO.File(CatalogCategories, "Main.jpg")).Into(MainImage);

I getting Error CS1503 Argument 1: cannot convert from 'Java.IO.File' to 'string'


Solution

  • The LoadFile method's parameter should be string.

    /// <summary>
    /// Constructs a new TaskParameter to load an image from a file.
    /// </summary>
    /// <returns>The new TaskParameter.</returns>
    /// <param name="filepath">Path to the file.</param>
    TaskParameter LoadFile(string filepath);
    

    You need use File's AbsolutePath property to get the string path:

    ImageService.Instance.LoadFile(new Java.IO.File(CatalogCategories, "Main.jpg").AbsolutePath).Into(MainImage);
    

    Update

    The Into method's parameter should be ImageViewAsync, so you should use ImageViewAsync in your layout:

    <FFImageLoading.Views.ImageViewAsync
        android:id="@+id/mainImage"
        android:scaleType="centerCrop"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
    

    In your .cs file:

    ImageViewAsync MainImage = FindViewById<ImageViewAsync>(Resource.Id.mainImage);