I am trying to load the contact images from a cursor, so I have the URI of each image.
But I would like to use the FFImageLoading library to add these images to the view, so that I can easily load placeholders and do a circle transform.
However, I am having difficulty using the library with a URI - I have tried converting the URI to a url using the Path to use the LoadFromURL method, but that has been unsuccessful.
So I am wondering if it would be better to use the LoadImage or LoadStream methods, but I am unsure how best to do so.
Here is what I essentially want to do
// use FFImageLoading library to asynchronously:
await ImageService
.Instance
.LoadUrl(item.PhotoURL, TimeSpan.FromHours(Settings.ImageCacheDurationHours)) // get the image from a URL
.LoadingPlaceholder("placeholderProfileImage.png") // specify a placeholder image
.Transform(new CircleTransformation()) // transform the image to a circle
.Error(e => System.Diagnostics.Debug.WriteLine(e.Message))
.IntoAsync(viewHolder.ProfilePhotoImageView);
However, for the images I get from the contacts, I have a Uri and I can load it using the following, but I cant perform a transformation on it:
var contactUri = ContentUris.WithAppendedId(ContactsContract.Contacts.ContentUri, Contacts[position].LongId);
var contactPhotoUri = Android.Net.Uri.WithAppendedPath(contactUri, Android.Provider.Contacts.Photos.ContentDirectory);
viewHolder.ProfilePhotoImageView.SetImageURI(contactPhotoUri);
Also, for relevance here is how I get the contacts:
var uri = ContactsContract.Contacts.ContentUri;
string[] projection = {
ContactsContract.Contacts.InterfaceConsts.Id,
ContactsContract.Contacts.InterfaceConsts.DisplayName,
ContactsContract.Contacts.InterfaceConsts.PhotoId
};
// CursorLoader
var loader = new CursorLoader(activity, uri, projection, null, null, null);
var cursor = (ICursor)loader.LoadInBackground();
if (cursor.MoveToFirst())
{
do
{
Contacts.Add(new Contact
{
LongId = cursor.GetLong(cursor.GetColumnIndex(projection[0])),
LastName = cursor.GetString(cursor.GetColumnIndex(projection[1])),
PhotoUrl = cursor.GetString(cursor.GetColumnIndex(projection[2]))
});
} while (cursor.MoveToNext());
}