Android FFImageLoading使用URI(Xamarin)

我试图从光标加载联系人图像,所以我有每个图像的URI。

但是我想使用FFImageLoading库将这些图像添加到视图中,这样我就可以轻松加载占位符并进行圆形变换。

但是,我在使用带有URI的库时遇到了困难 – 我尝试使用Path将URI转换为url以使用LoadFromURL方法,但这种做法并不成功。

所以我想知道使用LoadImage或LoadStream方法是否更好,但我不确定如何最好地这样做。

这是我本来想要做的

// 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); 

但是,对于我从联系人获得的图像,我有一个Uri,我可以使用以下内容加载它,但我无法对其进行转换:

  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); 

此外,与此相关的是我如何获得联系人:

  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()); }