Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

Can't get photo after iOS 13.x

$
0
0

Hello, I have a view in my app which brings in photos from gallery where you tap them and they are displayed in a boxview. This worked fine until iOS 13.0 whick changed PHImageManager paths, but with some help from the forum I fixed it. Unfortunatelly, after updating Xamarin from version 4.0.0.482894 because modals were broken due to iOS 13.+, Although I get the thumbnails, when I tap them the images are not being shown.

This is my method:

public List<PhotoModel> GetImagesFromGallery()
        {
            try
            {
                PHFetchResult fetchResults = PHAsset.FetchAssets(PHAssetMediaType.Image, null);
                //List<UIImage> images = new List<UIImage>();
                var requestOptions = new PHImageRequestOptions
                {
                    Synchronous = false,
                    NetworkAccessAllowed = true,
                    ResizeMode = PHImageRequestOptionsResizeMode.None,
                    DeliveryMode = PHImageRequestOptionsDeliveryMode.HighQualityFormat,
                };

                var highResolutionRequestOptions = new PHImageRequestOptions
                {
                    Synchronous = false,
                    NetworkAccessAllowed = true,
                    ResizeMode = PHImageRequestOptionsResizeMode.None,
                    DeliveryMode = PHImageRequestOptionsDeliveryMode.HighQualityFormat
                };
                var galleryPhotos = new List<PhotoModel>();
                var sceenSize = UIScreen.MainScreen.Bounds;
                var height = (float)sceenSize.Height;
                var width = (float)sceenSize.Width;

                var thumbnailSIze = new CGSize((nfloat)150, (nfloat)150);


                for (int i = 0; i < fetchResults.Count; i++)
                {
                    var fetchResult = fetchResults[i] as PHAsset;

                    var assetResources= PHAssetResource.GetAssetResources(fetchResult);
                    Regex fileURLpattern = new Regex(@"file:.*");
                    var path = string.Empty;
                    foreach (var assetResource in assetResources)
                    {
                        var des = assetResource.DebugDescription;
                        Match patternUrlMatch = fileURLpattern.Match(des);
                        path = patternUrlMatch.Groups[0].Value;
                    }

                    var photo = new PhotoModel();

                    PHImageManager.DefaultManager.RequestImageData(fetchResult, highResolutionRequestOptions, (data, dataUti, orientation, info) =>
                    {
                        //var newpath = (info?[(NSString)@"PHImageFileUTIKey"] as NSUrl).FilePathUrl.Path;
                        //Stream stream = System.IO.OpenRead((String)path);
                        var newpath = path.Replace("file://", string.Empty);
                        photo.FilePath = newpath;
                    });

                    PHImageManager.DefaultManager.RequestImageForAsset(fetchResult, thumbnailSIze,
                        PHImageContentMode.AspectFill, requestOptions, (img, info) =>
                        {
                            photo.ImageSource = ImageSource.FromStream(() =>
                            {
                                var stream = img.AsPNG().AsStream();
                                return stream;
                            });
                        });
            galleryPhotos.Add(photo);
                }

                return galleryPhotos;
            }
            catch (Exception ex)
            {
                var eadx = ex;
                throw;
            }
        }

The problem appears to be on the stream, as in the debbuger, photo.ImageSource appears to be null. Anyone facing the same problem or with a solution? I have tried many possible changes without any success.

Important mention: When I tried putting a direct path of an image to my image source property in xaml, the image was displayed.


Viewing all articles
Browse latest Browse all 204402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>