private void FeetchAddPhotos()
        {
            PHPhotoLibrary.RequestAuthorization(status => {
                if (status != PHAuthorizationStatus.Authorized)
                {
                    return;
                }

                var galleryTemp = new List <PHAssetCollection>();

                var allAlbums   = PHAssetCollection.FetchAssetCollections(PHAssetCollectionType.Album, PHAssetCollectionSubtype.Any, null).Cast <PHAssetCollection>();
                var smartAlbums = PHAssetCollection.FetchAssetCollections(PHAssetCollectionType.SmartAlbum, PHAssetCollectionSubtype.SmartAlbumUserLibrary, null).Cast <PHAssetCollection>();

                galleryTemp.AddRange(allAlbums);
                galleryTemp.AddRange(smartAlbums);

                var gallerySort = galleryTemp.OrderBy(obj => obj.LocalizedTitle);

                NSOperationQueue.MainQueue.AddOperation(() => {
                    foreach (var itemRaw in gallerySort)
                    {
                        var sortOptions             = new PHFetchOptions();
                        sortOptions.SortDescriptors = new NSSortDescriptor[] { new NSSortDescriptor("creationDate", false) };

                        var items = PHAsset.FetchAssets(itemRaw, sortOptions).Cast <PHAsset>().ToList();

                        if (items.Count > 0)
                        {
                            var colec = new GalleryNative()
                            {
                                Collection = itemRaw,
                            };
                            colec.Images.Add(new PhotoSetNative());

                            foreach (var item in items)
                            {
                                var newPhoto = new PhotoSetNative();
                                newPhoto.galleryImageXF.OriginalPath = item.LocalIdentifier;
                                newPhoto.Image = item;
                                colec.Images.Add(newPhoto);
                            }
                            galleryDirectories.Add(colec);
                        }
                    }

                    tableView.ReloadData();

                    if (galleryDirectories.Count > 0)
                    {
                        CurrentParent = 0;
                        IF_ItemSelectd(CurrentParent);
                    }
                });
            });
        }
Exemple #2
0
        async void BttCapture_TouchUpInside(object sender, EventArgs e)
        {
            var videoConnection = stillImageOutput.ConnectionFromMediaType(AVMediaType.Video);
            var sampleBuffer    = await stillImageOutput.CaptureStillImageTaskAsync(videoConnection);

            var jpegImageAsNsData = AVCaptureStillImageOutput.JpegStillToNSData(sampleBuffer);

            var image           = UIKit.UIImage.LoadFromData(jpegImageAsNsData).ResizeImage(syncPhotoOptions);
            var jpegAsByteArray = image.AsJPEG(syncPhotoOptions.Quality).ToArray();

            var result = new PhotoSetNative();

            result.galleryImageXF.Checked       = true;
            result.galleryImageXF.ImageRawData  = jpegAsByteArray;
            result.galleryImageXF.AsyncStatus   = Models.ImageAsyncStatus.InLocal;
            result.galleryImageXF.ImageSourceXF = ImageSource.FromStream(() => new System.IO.MemoryStream(jpegAsByteArray));

            MessagingCenter.Send <XFCameraController, List <PhotoSetNative> >(this, Utils.SubscribeImageFromCamera, new List <PhotoSetNative>()
            {
                result
            });
            DismissModalViewController(true);
        }
Exemple #3
0
        public void BindDataToCell(PhotoSetNative photoSetNative, IGalleryPickerSelected action, int index, bool IsCamera)
        {
            imgIcon.ClipsToBounds = true;
            bttClick.Hidden       = false;

            if (IsCamera)
            {
                imgIcon.Image       = UIImage.FromBundle("camera").ImageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal);
                imgIcon.ContentMode = UIViewContentMode.ScaleAspectFit;
                CheckBox.Hidden     = true;
                bttClick.Tag        = index;

                if (ActionClick == null)
                {
                    ActionClick = delegate {
                        action.IF_CameraSelected((int)CheckBox.Tag);
                    };
                    bttClick.TouchUpInside += (sender, e) =>
                    {
                        ActionClick();
                    };
                }
            }
            else
            {
                imgIcon.ContentMode = UIViewContentMode.ScaleAspectFill;
                CheckBox.Hidden     = false;
                CheckBox.Checked    = photoSetNative.galleryImageXF.Checked;
                CheckBox.Tag        = index;

                if (photoSetNative.galleryImageXF.Checked)
                {
                    bttClick.BackgroundColor = UIColor.DarkGray.ColorWithAlpha(0.5f);
                }
                else
                {
                    bttClick.BackgroundColor = UIColor.Clear;
                }

                var options = new PHImageRequestOptions
                {
                    Synchronous  = true,
                    DeliveryMode = PHImageRequestOptionsDeliveryMode.HighQualityFormat
                };

                PHImageManager.DefaultManager.RequestImageForAsset(
                    photoSetNative.Image,
                    new CoreGraphics.CGSize(250, 250),
                    PHImageContentMode.AspectFit,
                    options,
                    (result, info) => {
                    imgIcon.Image = result;
                }
                    );


                if (ActionClick == null)
                {
                    ActionClick = delegate {
                        var stream = imgIcon.Image.AsJPEG().AsStream().ToByteArray();
                        action.IF_ImageSelected(0, (int)CheckBox.Tag, ImageSource.FromStream(() => new System.IO.MemoryStream(stream)));
                    };
                    CheckBox.TouchUpInside += (sender, e) =>
                    {
                        ActionClick();
                    };
                }
            }
        }