Java Android使用URI(Xamarin)加载图像

Java Android使用URI(Xamarin)加载图像,java,c#,xamarin,xamarin.android,ffimageloading,Java,C#,Xamarin,Xamarin.android,Ffimageloading,我试图从光标加载联系人图像,因此我有每个图像的URI 但是我想使用FFImageLoading库将这些图像添加到视图中,这样我就可以轻松地加载占位符并进行圆变换 但是,我在使用带有URI的库时遇到了困难-我尝试使用LoadFromURL方法的路径将URI转换为url,但没有成功 因此,我想知道使用LoadImage或LoadStream方法是否更好,但我不确定如何最好地这样做 这就是我想要做的 // use FFImageLoading library to asynchronously

我试图从光标加载联系人图像,因此我有每个图像的URI

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

但是,我在使用带有URI的库时遇到了困难-我尝试使用LoadFromURL方法的路径将URI转换为url,但没有成功

因此,我想知道使用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());
    }

FFImageLoading不支持
content://somecontent
URL。您需要获取联系人图像流,例如使用以下帮助器方法:不要忘记添加适当的
CacheKey(“联系人id或其他”
),因为
LoadStream
默认情况下不使用缓存键。