0

I can't load image from an ImageCached object on iOS.

I got an asset-library url from the ALAsset but when I create the ImageCached object it d'ont show the image, ending with error that file is not found.

I take the image url from (ALAsset)asset.AssetUrl.AbsoluteString

Here is the bit of code that init my CachedObject

CachedImage image = new CachedImage();
image.Source = url;
image.HeightRequest = heightRequest;
image.WidthRequest = widthRequest;
image.DownsampleWidth = downSample;
image.CacheDuration = TimeSpan.FromDays(30);
image.LoadingPlaceholder = "Images/loading_grey.png";
image.ErrorPlaceholder = "Images/placeholder.png";
image.Transformations = new System.Collections.Generic.List<ITransformation>() {
    new CropTransformation(1, image.Width / 2 - heightRequest, image.Height / 2 - widthRequest)
};
image.CacheType = FFImageLoading.Cache.CacheType.Disk;
image.GestureRecognizers.Add(new TapGestureRecognizer
{
    Command = new Command(() => {
        Navigation.PushModalAsync(new ViewImagePage(url));
    }),
    NumberOfTapsRequired = 1
});
return image;

From an another posts i got a trail with this when i browse my image

ImagesNames.Add(asset.DefaultRepresentation.Url.AbsoluteString);

But image Path just link to asset.JPG that doesn't point to the file enter image description here

Cœur
  • 37,241
  • 25
  • 195
  • 267
Bobby
  • 80
  • 11
  • Did you set any Build Action on your images? It should be BundleResource to be packaged into your app – Gerald Versluis Sep 13 '16 at 17:45
  • Images are from the device library, taken with camera not in application. – Bobby Sep 13 '16 at 18:02
  • Do you get any error or something at all? I think it should ask for permissions to the Photos Library when you do? Maybe you should add some entry to your info.plist? Also the [ALAsset is deprecated](https://developer.apple.com/reference/assetslibrary/alasset) according to the Apple docs you should now use [PHAsset](https://developer.apple.com/reference/photos/phasset) – Gerald Versluis Sep 13 '16 at 18:04
  • No error, just that when i debug i see that the actual path that i got have asset-library in Url, and ffimageloading don't take it as an valide Url. After some search i see a method to get the image Path, but again return value doesn't seems to be the good one. – Bobby Sep 13 '16 at 18:11
  • @Bobby `FFImageLoading` does not support loading images from `ALAssetsLibrary` (no refs in the source to it). Also the Assets Library framework is deprecated, you should look at using the iOS Photos framework instead. If you want to "cache" these assets, you will need to get a PHAsset stream and use FFImageLoading's `ImageService.Instance.LoadStream` to cache/load them, remember iOS might have to download the asset as it could be stored off the phone itself. Also you will need to preform a RequestAuthorization to ask the use to grant access to the Photo assets. – SushiHangover Sep 13 '16 at 19:18
  • @SushiHangover PHAsset seems to be the solution, like Gerald says too. I will try to recode with it. – Bobby Sep 13 '16 at 20:05

0 Answers0