Exemplo n.º 1
0
            void PhotoEnumerator(ALAsset result, nint index, ref bool stop)
            {
                if (result == null)
                {
                    return;
                }

                ELCAsset elcAsset = new ELCAsset(this, result);

                bool isAssetFiltered = false;

                /*if (self.assetPickerFilterDelegate &&
                 * [self.assetPickerFilterDelegate respondsToSelector:@selector(assetTablePicker:isAssetFilteredOut:)])
                 * {
                 * isAssetFiltered = [self.assetPickerFilterDelegate assetTablePicker:self isAssetFilteredOut:(ELCAsset*)elcAsset];
                 * }*/

                if (result.DefaultRepresentation == null)
                {
                    isAssetFiltered = true;
                }

                if (!isAssetFiltered)
                {
                    ElcAssets.Add(elcAsset);
                }
            }
Exemplo n.º 2
0
        /// <summary>
        /// Synchronouses the get asset.
        /// </summary>
        /// <returns>The get asset.</returns>
        /// <param name="filename">Filename.</param>
        public ALAsset SynchronousGetAsset(string filename)
        {
            ManualResetEvent waiter = new ManualResetEvent(false);
            NSError          error  = null;
            ALAsset          result = null;
            Exception        exception;

            ThreadPool.QueueUserWorkItem((object state) => _assetLibrary.AssetForUrl(new NSUrl(filename), (ALAsset asset) =>
            {
                result = asset;
                waiter.Set();
            },
                                                                                     e =>
            {
                error = e;
                waiter.Set();
            }));


            if (!waiter.WaitOne(TimeSpan.FromSeconds(10)))
            {
                throw new Exception("Error Getting Asset : Timeout, Asset=" + filename);
            }

            if (error != null)
            {
                throw new Exception(error.Description);
            }

            return(result);
        }
Exemplo n.º 3
0
        private bool SelectImageIfPossible(ALAsset asset, int sectionIndex)
        {
            if (SelectedImages.Count == 10)
            {
                SetToasterText("You can select a maximum of 10 images");
                return(false);
            }
            SelectedImages.Add(asset);
            UpdateNavigationBar();

            bool allSectionImageSelected = true;

            foreach (var image in Sections[sectionIndex].Images)
            {
                if (!SelectedImages.Contains(image.Asset))
                {
                    allSectionImageSelected = false;
                    break;
                }
            }

            if (allSectionImageSelected)
            {
                Sections[sectionIndex].Selected = true;
                using (var headerKind = new NSString("UICollectionElementKindSectionHeader"))
                {
                    if (CollectionView.GetSupplementaryView(headerKind, NSIndexPath.FromItemSection(0, sectionIndex)) is SelectableDateCollectionHeaderView header)
                    {
                        header.UpdateSelectedState(true, true);
                    }
                }
            }

            return(true);
        }
Exemplo n.º 4
0
        public static void setCurrentPhotoToIndex(int index)
        {
            currentAsset = photoAssets [index];
            ALAssetRepresentation rep = currentAsset.RepresentationForUti("public.jpeg");
            CGImage imageRef          = rep.GetFullScreenImage();

            if (imageRef != null)
            {
                currentPhotoImage = UIImage.FromImage(imageRef);
                currentPhotoIndex = index;
            }
        }
        bool ShouldSelectAsset(ALAsset asset, int previousCount)
        {
            var shouldSelect = MaximumImagesCount <= 0 || previousCount < MaximumImagesCount;

            if (!shouldSelect)
            {
                string title   = String.Format("Only {0} photos please!", MaximumImagesCount);
                string message = String.Format("You can only send {0} photos at a time.", MaximumImagesCount);
                var    alert   = new UIAlertView(title, message, null, null, "Ok");
                alert.Show();
            }
            return(shouldSelect);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Assets the enumerator.
        /// </summary>
        /// <param name="asset">Asset.</param>
        /// <param name="index">Index.</param>
        /// <param name="shouldStop">Should stop.</param>
        private void AssetEnumerator(ALAsset asset, nint index, ref bool shouldStop)
        {
            if (asset == null)
            {
                shouldStop = true;
                return;
            }

            if (!shouldStop)
            {
                // add asset name to list
                _assets.Add(asset.AssetUrl.ToString());
                shouldStop = false;
            }
        }
		/// <summary>
		/// A simple asset enumerator that adds the asset to our asset list
		/// </summary>
		protected void AssetEnumerator (ALAsset asset, nint index, ref bool stop)
		{
		    // when the enumeration is completed, this method is invoked with group set to null
			if(asset != null) {
				Console.WriteLine ("Found asset: " + index.ToString ());

				// add the asset to the group list
				assetGroups[currentGroup].Add (asset);

				// keep going
				stop = false;

				//Console.WriteLine(asset.AssetType.ToString());
			}
			else
				Console.WriteLine("Asset enumeration completed.");
		}
Exemplo n.º 8
0
        public AssetImage(ALAsset asset)
        {
            Asset = asset;
            Date  = asset.Date.ToDateTime().Date;

            if (Asset.Thumbnail != null)
            {
                Thumbnail = Asset.Thumbnail;
            }
            else
            {
                var rep = Asset.DefaultRepresentation;
                if (rep != null)
                {
                    Thumbnail = rep.GetFullScreenImage();
                }
            }
        }
        private void AssetEnumerator(ALAsset asset, nint index, ref bool shouldStop)
        {
            if (asset == null)
            {
                shouldStop = true;
                return;
            }
            if (!shouldStop)
            {
                var picture = new Picture {
                    ThumbnailHandle = asset.Thumbnail.Handle,
                    Uri             = asset.AssetUrl.ToString()
                };

                pictures.Add(picture);
                shouldStop = false;
            }
        }
Exemplo n.º 10
0
        private void UnselectImage(ALAsset asset, int sectionIndex)
        {
            SelectedImages.Remove(asset);
            UpdateNavigationBar();

            if (!Sections[sectionIndex].Selected)
            {
                return;
            }
            Sections[sectionIndex].Selected = false;
            using (var headerKind = new NSString("UICollectionElementKindSectionHeader"))
            {
                if (CollectionView.GetSupplementaryView(headerKind, NSIndexPath.FromItemSection(0, sectionIndex)) is SelectableDateCollectionHeaderView header)
                {
                    header.UpdateSelectedState(false, true);
                }
            }
        }
Exemplo n.º 11
0
        public static void setCurrentPhotoToIndex(int index)
        {
            currentAsset = photoAssets [index];
            ALAssetRepresentation rep = currentAsset.RepresentationForUti("public.jpeg");

            // image might not be available as a JPEG
            if (rep == null)
            {
                return;
            }
            CGImage imageRef = rep.GetFullScreenImage();

            if (imageRef == null)
            {
                return;
            }
            currentPhotoImage = UIImage.FromImage(imageRef);
            currentPhotoIndex = index;
        }
            private void PhotoEnumerator(ALAsset result, nint index, ref bool stop)
            {
                if (result == null)
                {
                    return;
                }

                var isAssetFiltered = false;

                if (result.DefaultRepresentation == null)
                {
                    isAssetFiltered = true;
                }

                if (!isAssetFiltered)
                {
                    assets.Add(result);
                }
            }
Exemplo n.º 13
0
        /// <summary>
        /// A simple asset enumerator that adds the asset to our asset list
        /// </summary>
        protected void AssetEnumerator(ALAsset asset, nint index, ref bool stop)
        {
            // when the enumeration is completed, this method is invoked with group set to null
            if (asset != null)
            {
                Console.WriteLine("Found asset: " + index.ToString());

                // add the asset to the group list
                assetGroups[currentGroup].Add(asset);

                // keep going
                stop = false;

                //Console.WriteLine(asset.AssetType.ToString());
            }
            else
            {
                Console.WriteLine("Asset enumeration completed.");
            }
        }
        bool ShouldSelectAsset(ALAsset asset, int previousCount)
        {
            var shouldSelect = MaximumImagesCount <= 0 || previousCount < MaximumImagesCount;

            if (!shouldSelect)
            {
                var first  = NSBundle.MainBundle.GetLocalizedString("Only", "Only");
                var second = NSBundle.MainBundle.GetLocalizedString("photos please", "photos please!");

                var title = $"{first} {MaximumImagesCount} {second}";

                var third  = NSBundle.MainBundle.GetLocalizedString("You can only send", "You can only send");
                var fourth = NSBundle.MainBundle.GetLocalizedString("photos at a time", "photos at a time.");

                var message = $"{third} {MaximumImagesCount} {fourth}";
                var alert   = new UIAlertView(title, message, null, null, NSBundle.MainBundle.GetLocalizedString("Okay", "Okay"));
                alert.Show();
            }
            return(shouldSelect);
        }
Exemplo n.º 15
0
        bool ShouldSelectAsset(ALAsset asset, int previousCount)
        {
            var shouldSelect = MaximumImagesCount <= 0 || previousCount < MaximumImagesCount;

            if (!shouldSelect)
            {
                var first  = NSBundle.MainBundle.LocalizedString("Only", "Only");
                var second = NSBundle.MainBundle.LocalizedString("photos please", "photos please!");

                string title = String.Format("{0} {1} {2}", first, MaximumImagesCount, second);

                var third  = NSBundle.MainBundle.LocalizedString("You can only send", "You can only send");
                var fourth = NSBundle.MainBundle.LocalizedString("photos at a time", "photos at a time.");

                string message = String.Format("{0} {1} {2}", third, MaximumImagesCount, fourth);
                var    alert   = new UIAlertView(title, message, null, null, NSBundle.MainBundle.LocalizedString("Okay", "Okay"));
                alert.Show();
            }
            return(shouldSelect);
        }
Exemplo n.º 16
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Gallery.iOS.PhotoController"/> class.
        /// </summary>
        public PhotoController(ALAsset asset) : base("PhotoController", null)
        {
            _imageView = new UIImageView()
            {
                TranslatesAutoresizingMaskIntoConstraints = false,
                ContentMode = UIViewContentMode.ScaleAspectFit
            };

            _titleLabel = new UILabel()
            {
                TranslatesAutoresizingMaskIntoConstraints = false,
            };

            _dateLabel = new UILabel()
            {
                TranslatesAutoresizingMaskIntoConstraints = false,
            };

            _imageView.Image = new UIImage(asset.DefaultRepresentation.GetFullScreenImage());
            _titleLabel.Text = asset.DefaultRepresentation.Filename;
            _dateLabel.Text  = asset.Date.ToString();
        }
Exemplo n.º 17
0
        private MediaFile GetPictureMediaFile(ALAsset asset, long index = 0)
        {
            var rep = asset.DefaultRepresentation;

            if (rep == null)
            {
                return(null);
            }

            var cgImage = rep.GetImage();

            var path = MediaPickerDelegate.GetOutputPath(MediaImplementation.TypeImage,
                                                         _options.Directory ?? "temp",
                                                         _options.Name, index);

            var image = new UIImage(cgImage, 1.0f, (UIImageOrientation)rep.Orientation);

            cgImage?.Dispose();
            cgImage = null;
            rep?.Dispose();
            rep = null;

            image.AsJPEG().Save(path, true);

            image?.Dispose();
            image = null;
            GC.Collect(GC.MaxGeneration, GCCollectionMode.Default);

            string aPath = null;
            //try to get the album path's url
            var url = asset.AssetUrl;

            aPath = url?.AbsoluteString;

            return(new MediaFile(path, () => File.OpenRead(path), albumPath: aPath));
        }
        private MediaFile GetPictureMediaFile(ALAsset asset, long index = 0)
        {
            var rep = asset.DefaultRepresentation;

            if (rep == null)
            {
                return(null);
            }

            var cgImage = rep.GetImage();

            UIImage image = null;

            if (cgImage == null)
            {
                var fetch     = PHAsset.FetchAssets(new[] { asset.AssetUrl }, null);
                var ph        = fetch.firstObject as PHAsset;
                var manager   = PHImageManager.DefaultManager;
                var phOptions = new PHImageRequestOptions
                {
                    Version = PHImageRequestOptionsVersion.Original,
                    NetworkAccessAllowed = true,
                    Synchronous          = true
                };

                phOptions.ProgressHandler = (double progress, NSError error, out bool stop, NSDictionary info) =>
                {
                    Debug.WriteLine($"Progress: {progress.ToString()}");

                    stop = false;
                };

                if (UIDevice.CurrentDevice.CheckSystemVersion(13, 0))
                {
                    manager.RequestImageDataAndOrientation(ph, phOptions, (data, i, orientation, k) =>
                    {
                        if (data != null)
                        {
                            image = new UIImage(data, 1.0f);
                        }
                    });
                }
                else
                {
                    manager.RequestImageData(ph, phOptions, (data, i, orientation, k) =>
                    {
                        if (data != null)
                        {
                            image = new UIImage(data, 1.0f);
                        }
                    });
                }
                phOptions?.Dispose();
                fetch?.Dispose();
                ph?.Dispose();
            }
            else
            {
                image = new UIImage(cgImage, 1.0f, (UIImageOrientation)rep.Orientation);
            }

            var path = MediaPickerDelegate.GetOutputPath(MediaImplementation.TypeImage,
                                                         options.Directory ?? "temp",
                                                         options.Name, asset.AssetUrl?.PathExtension, index);

            cgImage?.Dispose();
            cgImage = null;
            rep?.Dispose();
            rep = null;

            //There might be cases when the original image cannot be retrieved while image thumb was still present.
            //Then no need to try to save it as we will get an exception here
            //TODO: Ideally, we should notify the client that we failed to get original image
            //TODO: Otherwise, it might be confusing to the user, that he saw the thumb, but did not get the image
            if (image == null)
            {
                return(null);
            }

            image.AsJPEG().Save(path, true);

            image?.Dispose();
            image = null;
            GC.Collect(GC.MaxGeneration, GCCollectionMode.Default);

            string aPath = null;
            //try to get the album path's url
            var url = asset.AssetUrl;

            aPath = url?.AbsoluteString;

            return(new MediaFile(path, () => File.OpenRead(path), albumPath: aPath));
        }
Exemplo n.º 19
0
		public static void setCurrentPhotoToIndex (int index)
		{
			currentAsset = photoAssets [index];
			ALAssetRepresentation rep = currentAsset.RepresentationForUti ("public.jpeg");
			CGImage imageRef = rep.GetFullScreenImage ();
			if (imageRef != null) {
				currentPhotoImage = UIImage.FromImage (imageRef);
				currentPhotoIndex = index;
			}
		}
Exemplo n.º 20
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Intranel.Mobile.Touch.AssetLibraryReadStream"/> class.
 /// </summary>
 public AssetLibraryReadStream(ALAsset asset, ALAssetsLibrary assetLibrary)
 {
     AssetRep   = asset.DefaultRepresentation;
     Lib        = assetLibrary;
     m_Position = 0;
 }
 bool ShouldSelectAsset(ALAsset asset, int previousCount)
 {
     var shouldSelect = MaximumImagesCount <= 0 || previousCount < MaximumImagesCount;
     if (!shouldSelect) {
         string title = Catalog.Format (Catalog.GetString ("Only {0} photos please!"), MaximumImagesCount);
         string message = Catalog.Format (Catalog.GetString ("You can only send {0} photos at a time."), MaximumImagesCount);
         var alert = new UIAlertView (title, message, null, null, Catalog.GetString ("Okay"));
         alert.Show ();
     }
     return shouldSelect;
 }
Exemplo n.º 22
0
 public ELCAsset(ELCAssetTablePicker parent, ALAsset asset)
 {
     _Parent = new WeakReference(parent);
     Asset   = asset;
 }
Exemplo n.º 23
0
        private MediaFile GetPictureMediaFile(ALAsset asset, long index = 0)
        {
            var rep = asset.DefaultRepresentation;

            if (rep == null)
            {
                return(null);
            }

            var cgImage = rep.GetImage();

            UIImage image = null;

            if (cgImage == null)
            {
                var fetch     = PHAsset.FetchAssets(new[] { asset.AssetUrl }, null);
                var ph        = fetch.firstObject as PHAsset;
                var manager   = PHImageManager.DefaultManager;
                var phOptions = new PHImageRequestOptions
                {
                    Version = PHImageRequestOptionsVersion.Original,
                    NetworkAccessAllowed = true,
                    Synchronous          = true
                };

                phOptions.ProgressHandler = (double progress, NSError error, out bool stop, NSDictionary info) =>
                {
                    Debug.WriteLine($"Progress: {progress.ToString()}");

                    stop = false;
                };

                manager.RequestImageData(ph, phOptions, (data, i, orientation, k) =>
                {
                    if (data != null)
                    {
                        image = new UIImage(data, 1.0f);
                    }
                });
                phOptions?.Dispose();
                fetch?.Dispose();
                ph?.Dispose();
            }
            else
            {
                image = new UIImage(cgImage, 1.0f, (UIImageOrientation)rep.Orientation);
            }

            var path = MediaPickerDelegate.GetOutputPath(MediaImplementation.TypeImage,
                                                         options.Directory ?? "temp",
                                                         options.Name, asset.AssetUrl?.PathExtension, index);

            cgImage?.Dispose();
            cgImage = null;
            rep?.Dispose();
            rep = null;

            image.AsJPEG().Save(path, true);

            image?.Dispose();
            image = null;
            GC.Collect(GC.MaxGeneration, GCCollectionMode.Default);

            string aPath = null;
            //try to get the album path's url
            var url = asset.AssetUrl;

            aPath = url?.AbsoluteString;

            return(new MediaFile(path, () => File.OpenRead(path), albumPath: aPath));
        }
Exemplo n.º 24
0
        private MediaFile GetPictureMediaFile(ALAsset asset)
        {
            var rep = asset.DefaultRepresentation;

            if (rep == null)
            {
                return(null);
            }

            var cgImage = rep.GetImage();

            var path = MediaPickerDelegate.GetOutputPath(MediaImplementation.TypeImage,
                                                         _options.Directory ?? "temp",
                                                         _options.Name);

            var image = new UIImage(cgImage, 1.0f, (UIImageOrientation)rep.Orientation);

            var percent = 1.0f;

            if (_options.PhotoSize != PhotoSize.Full)
            {
                try
                {
                    switch (_options.PhotoSize)
                    {
                    case PhotoSize.Large:
                        percent = .75f;
                        break;

                    case PhotoSize.Medium:
                        percent = .5f;
                        break;

                    case PhotoSize.Small:
                        percent = .25f;
                        break;

                    case PhotoSize.Custom:
                        percent = (float)_options.CustomPhotoSize / 100f;
                        break;
                    }

                    if (_options.PhotoSize == PhotoSize.MaxWidthHeight && _options.MaxWidthHeight.HasValue)
                    {
                        var max = Math.Max(image.CGImage.Width, image.CGImage.Height);
                        if (max > _options.MaxWidthHeight.Value)
                        {
                            percent = (float)_options.MaxWidthHeight.Value / (float)max;
                        }
                    }

                    if (percent < 1.0f)
                    {
                        //begin resizing image
                        image = image.ResizeImageWithAspectRatio(percent);
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine($"Unable to compress image: {ex}");
                }
            }


            NSDictionary meta = null;

            try
            {
                //meta = PhotoLibraryAccess.GetPhotoLibraryMetadata(asset.AssetUrl);

                //meta = info[UIImagePickerController.MediaMetadata] as NSDictionary;
                if (meta != null && meta.ContainsKey(ImageIO.CGImageProperties.Orientation))
                {
                    var newMeta = new NSMutableDictionary();
                    newMeta.SetValuesForKeysWithDictionary(meta);
                    var newTiffDict = new NSMutableDictionary();
                    newTiffDict.SetValuesForKeysWithDictionary(meta[ImageIO.CGImageProperties.TIFFDictionary] as NSDictionary);
                    newTiffDict.SetValueForKey(meta[ImageIO.CGImageProperties.Orientation], ImageIO.CGImageProperties.TIFFOrientation);
                    newMeta[ImageIO.CGImageProperties.TIFFDictionary] = newTiffDict;

                    meta = newMeta;
                }
                var location = _options.Location;
                if (meta != null && location != null)
                {
                    meta = MediaPickerDelegate.SetGpsLocation(meta, location);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Unable to get metadata: {ex}");
            }

            //iOS quality is 0.0-1.0
            var quality    = (_options.CompressionQuality / 100f);
            var savedImage = false;

            if (meta != null)
            {
                savedImage = MediaPickerDelegate.SaveImageWithMetadata(image, quality, meta, path);
            }

            if (!savedImage)
            {
                image.AsJPEG(quality).Save(path, true);
            }


            string aPath = null;
            //try to get the album path's url
            var url = asset.AssetUrl;

            aPath = url?.AbsoluteString;

            return(new MediaFile(path, () => File.OpenRead(path), albumPath: aPath));
        }
 public ELCAsset(ELCAssetTablePicker parent, ALAsset asset)
 {
     _Parent = new WeakReference (parent);
     Asset = asset;
 }
            void PhotoEnumerator(ALAsset result, nint index, ref bool stop)
            {
                if (result == null) {
                    return;
                }

                ELCAsset elcAsset = new ELCAsset (this, result);

                bool isAssetFiltered = false;
                /*if (self.assetPickerFilterDelegate &&
                    [self.assetPickerFilterDelegate respondsToSelector:@selector(assetTablePicker:isAssetFilteredOut:)])
                {
                    isAssetFiltered = [self.assetPickerFilterDelegate assetTablePicker:self isAssetFilteredOut:(ELCAsset*)elcAsset];
                }*/

                if (result.DefaultRepresentation == null)
                    isAssetFiltered = true;

                if (!isAssetFiltered) {
                    ElcAssets.Add (elcAsset);
                }
            }
Exemplo n.º 27
0
		public static void setCurrentPhotoToIndex (int index)
		{
			currentAsset = photoAssets [index];
			ALAssetRepresentation rep = currentAsset.RepresentationForUti ("public.jpeg");
			// image might not be available as a JPEG
			if (rep == null)
				return;
			CGImage imageRef = rep.GetFullScreenImage ();
			if (imageRef == null)
				return;
			currentPhotoImage = UIImage.FromImage (imageRef);
			currentPhotoIndex = index;
		}
        bool ShouldSelectAsset(ALAsset asset, int previousCount)
        {
            var shouldSelect = MaximumImagesCount <= 0 || previousCount < MaximumImagesCount;
            if (!shouldSelect) {
                var first = NSBundle.MainBundle.LocalizedString ("Only", "Only");
                var second = NSBundle.MainBundle.LocalizedString ("photos please", "photos please!");

                string title = String.Format ("{0} {1} {2}", first, MaximumImagesCount, second);

                var third = NSBundle.MainBundle.LocalizedString ("You can only send", "You can only send");
                var fourth = NSBundle.MainBundle.LocalizedString ("photos at a time", "photos at a time.");

                string message = String.Format ("{0} {1} {2}", third, MaximumImagesCount, fourth);
                var alert = new UIAlertView (title, message, null, null, NSBundle.MainBundle.LocalizedString ("Okay", "Okay"));
                alert.Show ();
            }
            return shouldSelect;
        }
Exemplo n.º 29
0
		/// <summary>
		/// Initializes a new instance of the <see cref="Intranel.Mobile.Touch.AssetLibraryReadStream"/> class.
		/// </summary>
		public AssetLibraryReadStream(ALAsset asset, ALAssetsLibrary assetLibrary)
		{
			AssetRep = asset.DefaultRepresentation;
			Lib = assetLibrary;
			m_Position = 0;
		}