private static UIImage GetImage(PHAsset asset) { UIImage result = null; var options = new PHImageRequestOptions { Synchronous = true, NetworkAccessAllowed = true }; nfloat scale = UIScreen.MainScreen.Scale; var size = new CGSize(UIScreen.MainScreen.Bounds.Size.Width * scale, UIScreen.MainScreen.Bounds.Size.Height * scale); ImageCache.Instance.GetImage(asset, size, options, x => result = x); return result; }
private void UpdateImageAsset(PHAsset asset) { if (asset.MediaSubtypes == PHAssetMediaSubtype.PhotoLive) { _gradientView.Hidden = false; _gradientView.Image = UIImageExtensions.FromBundle(BundleAssets.Gradient); _iconView.Hidden = false; _durationLabel.Hidden = true; _iconView.Image = UIImageExtensions.FromBundle(BundleAssets.IconBadgeLivePhoto); } else { _gradientView.Hidden = true; _iconView.Hidden = true; _durationLabel.Hidden = true; } }
public void Update(Action handler = null) { List <PHFetchResult> albumListFetchResult = new List <PHFetchResult>(); InvokeInBackground(() => { foreach (var type in _assetCollectionTypes) { albumListFetchResult.AddRange(new List <PHFetchResult> { PHAssetCollection.FetchAssetCollections(type, PHAssetCollectionSubtype.Any, null) }); } this._albumList = new List <Item>(); var tmpAlbumList = new List <Item>(); var isAssetCollectionSubtypeAny = this._assetCollectionSubtypes.Contains(PHAssetCollectionSubtype.Any); foreach (var fetchResult in albumListFetchResult) { fetchResult.Enumerate((NSObject album, nuint index, out bool stop) => { var phAlbum = album as PHAssetCollection; if (this._assetCollectionSubtypes.Contains((album as PHAssetCollection).AssetCollectionSubtype) || isAssetCollectionSubtypeAny) { if (this._shouldShowEmptyAlbum || PHAsset.FetchAssets((album as PHAssetCollection), PhotoKitAssetList.FetchOptions(this._mediaType)).Count() != 0) { tmpAlbumList.Add(new PhotoKitAssetList(album as PHAssetCollection, this._mediaType)); } } stop = false; }); } if (this._assetCollectionTypes.Count() == 1 && this._assetCollectionTypes.Contains(PHAssetCollectionType.Moment)) { this._albumList = tmpAlbumList.OrderByDescending(x => x.Date.SecondsSinceReferenceDate).ToList(); } else { this._albumList = tmpAlbumList; } handler?.Invoke(); }); }
/// <inheritdoc /> protected override void Dispose(bool disposing) { if (disposing) { if (PHPhotoLibrary.AuthorizationStatus == PHAuthorizationStatus.Authorized) { PHPhotoLibrary.SharedPhotoLibrary.UnregisterChangeObserver(this); } _albumView.ClearPreview(); _asset.Dispose(); _asset = null; } base.Dispose(disposing); }
public override void ViewDidLoad() { base.ViewDidLoad(); NavigationItem.RightBarButtonItem = new UIBarButtonItem(UIBarButtonSystemItem.Add, AddAlbum); // Create a PHFetchResult object for each section in the table view. var allPhotosOptions = new PHFetchOptions { SortDescriptors = new NSSortDescriptor [] { new NSSortDescriptor("creationDate", true) }, }; allPhotos = PHAsset.FetchAssets(allPhotosOptions); smartAlbums = PHAssetCollection.FetchAssetCollections(PHAssetCollectionType.SmartAlbum, PHAssetCollectionSubtype.AlbumRegular, null); userCollections = PHCollection.FetchTopLevelUserCollections(null); PHPhotoLibrary.SharedPhotoLibrary.RegisterChangeObserver(this); }
PHAsset[] AssetsAtIndexPaths(Array indexPaths) { if (indexPaths.Length == 0) { return(null); } var assets = new PHAsset[indexPaths.Length]; for (int i = 0; i < indexPaths.Length; i++) { var asset = (PHAsset)AssetsFetchResults.ObjectAt(i); assets [i] = asset; } return(assets); }
public override void PrepareForSegue(UIStoryboardSegue segue, NSObject sender) { var destination = (segue.DestinationViewController as UINavigationController)?.TopViewController as AssetGridViewController; if (destination == null) { throw new InvalidProgramException("unexpected view controller for segue"); } var cell = (UITableViewCell)sender; destination.Title = cell.TextLabel.Text; switch (segue.Identifier) { case showAllPhotos: destination.FetchResult = allPhotos; break; case showCollection: // get the asset collection for the selected row var indexPath = TableView.IndexPathForCell(cell); NSObject collection = null; switch ((Section)indexPath.Section) { case Section.SmartAlbums: collection = smartAlbums.ObjectAt(indexPath.Row); break; case Section.UserCollections: collection = userCollections.ObjectAt(indexPath.Row); break; } // configure the view controller with the asset collection var assetCollection = collection as PHAssetCollection; if (assetCollection == null) { throw new InvalidProgramException("expected asset collection"); } destination.FetchResult = PHAsset.FetchAssets(assetCollection, null); destination.AssetCollection = assetCollection; break; } }
partial void BtnClick(UIKit.UIButton sender) { PHFetchResult fetchResults = PHAsset.FetchAssets(PHAssetMediaType.Image, null); for (int i = 0; i < fetchResults.Count; i++) { //fetching Result PHAsset phAsset = (PHAsset)fetchResults[i]; String fileName = (NSString)phAsset.ValueForKey((NSString)"filename"); PHImageManager.DefaultManager.RequestImageData(phAsset, null, (data, dataUti, orientation, info) => { var path = (info?[(NSString)@"PHImageFileURLKey"] as NSUrl).FilePathUrl.Path; //Stream stream = System.IO.OpenRead((String)path); Stream stream = new FileStream(path, FileMode.Open, FileAccess.Read); }); } }
/* * Task<ObservableCollection<Photo>> IPhotoImporter.Get(int startIndex, int count, Quality quality = Quality.Low) * { * throw new NotImplementedException(); * } * * Task<ObservableCollection<Photo>> IPhotoImporter.Get(List<string> filenames, Quality quality = Quality.Low) * { * throw new NotImplementedException(); * } */ private void RequestImage(ObservableCollection <Photo> photos, PHAsset asset, string filename, PHImageRequestOptions options) { PHImageManager.DefaultManager.RequestImageForAsset(asset, PHImageManager.MaximumSize, PHImageContentMode.AspectFill, options, (image, info) => { //Original code uses image.AsPNG() using (NSData imageData = image.AsJPEG()) { var bytes = new byte[imageData.Length]; System.Runtime.InteropServices.Marshal.Copy(imageData.Bytes, bytes, 0, Convert.ToInt32(imageData.Length)); var photo = new Photo() { Bytes = bytes, Filename = filename }; photos.Add(photo); } }); }
public void Bind(PHAsset asset) { this.Asset = asset; if (Asset.MediaType == PHAssetMediaType.Video) { _videoIcon.Hidden = false; _videoDuration.Hidden = false; _gradientView.Hidden = false; _videoDuration.Text = GetDurationWithFormat(Asset.Duration); } else { _videoIcon.Hidden = true; _videoDuration.Hidden = true; _gradientView.Hidden = true; } }
private void ChangeImage(PHAsset asset, PHImageManager imageManager, PHImageRequestOptions options) { var assetSize = new CGSize(asset.PixelWidth, asset.PixelHeight); DispatchQueue.DefaultGlobalQueue.DispatchAsync(() => imageManager?.RequestImageForAsset(asset, assetSize, PHImageContentMode.AspectFill, options, (result, info) => DispatchQueue.MainQueue.DispatchAsync(() => { CurrentMediaType = MediaType.Image; _albumView.ImageCropView.Hidden = false; _albumView.MovieView.Hidden = true; _albumView.ImageCropView.ImageSize = assetSize; _albumView.ImageCropView.Image = result; }))); }
public override void ViewDidLoad() { base.ViewDidLoad(); ResetCachedAssets(); PHPhotoLibrary.SharedPhotoLibrary.RegisterChangeObserver(this); // If we get here without a segue, it's because we're visible at app launch, // so match the behavior of segue from the default "All Photos" view. if (FetchResult == null) { var allPhotosOptions = new PHFetchOptions { SortDescriptors = new NSSortDescriptor[] { new NSSortDescriptor("creationDate", true) } }; FetchResult = PHAsset.FetchAssets(allPhotosOptions); } }
private static PHFetchResult FetchAssets() { const string sortType = "creationDate"; var assetsOptions = new PHFetchOptions { SortDescriptors = new[] { new NSSortDescriptor(sortType, false) }, FetchLimit = FetchLimit }; return(PHAssetCollection.FetchAssetCollections(PHAssetCollectionType.SmartAlbum, PHAssetCollectionSubtype.SmartAlbumUserLibrary, null).firstObject is PHAssetCollection assetCollection ? PHAsset.FetchAssets(assetCollection, assetsOptions) : PHAsset.FetchAssets(assetsOptions)); }
public static bool DeleteImagesFromGallery(string[] localIds) { var images = PHAsset.FetchAssetsUsingLocalIdentifiers(localIds, new PHFetchOptions()); var assets = images.Select(a => (PHAsset)a).ToArray(); var success = PHPhotoLibrary.SharedPhotoLibrary.PerformChangesAndWait ( () => { PHAssetChangeRequest.DeleteAssets(assets); }, out var error ); if (error != null) { Console.WriteLine(error); } return(success); }
public async Task <bool> CopyToDestination(PHAsset photo, string destPath, IFileSystem fileSystem, DateTime ft) { try { var origfilepath = await photo.GetIOSFilePath().ConfigureAwait(false); if (string.IsNullOrWhiteSpace(origfilepath)) { return(false); } var fs = new FileStream(origfilepath, FileMode.Open, FileAccess.Read); return(await CopyToDestination(fs, destPath, fileSystem, ft).ConfigureAwait(false)); } catch (Exception) { return(false); } }
public string GetFileDescription(string file) { if (string.IsNullOrEmpty(file)) { return(null); } long fileSize = 0; var asset = PHAsset.FetchAssets(new[] { new NSUrl(file) }, null).LastObject as PHAsset; if (asset != null) { var options = new PHImageRequestOptions { Synchronous = true }; PHImageManager.DefaultManager.RequestImageData(asset, options, (data, dataUti, orientation, info) => { fileSize = Convert.ToInt64(data.Length); }); } return(NSByteCountFormatter.Format(fileSize, NSByteCountFormatterCountStyle.Binary)); }
/// <summary> /// /// </summary> /// <param name="url"></param> /// <returns></returns> public static (NSDictionary, string) GetPhotoLibraryMetadata(NSUrl url) { NSDictionary meta = null; var image = PHAsset.FetchAssets(new NSUrl[] { url }, new PHFetchOptions()).firstObject as PHAsset; var imageManager = PHImageManager.DefaultManager; using (var requestOptions = new PHImageRequestOptions { Synchronous = true, NetworkAccessAllowed = true, DeliveryMode = PHImageRequestOptionsDeliveryMode.HighQualityFormat, }) { imageManager.RequestImageData(image, requestOptions, (data, dataUti, orientation, info) => { try { var fullimage = CIImage.FromData(data); if (fullimage?.Properties != null) { meta = new NSMutableDictionary { [ImageIO.CGImageProperties.Orientation] = new NSString(fullimage.Properties.Orientation.ToString()), [ImageIO.CGImageProperties.ExifDictionary] = fullimage.Properties.Exif?.Dictionary ?? new NSDictionary(), [ImageIO.CGImageProperties.TIFFDictionary] = fullimage.Properties.Tiff?.Dictionary ?? new NSDictionary(), [ImageIO.CGImageProperties.GPSDictionary] = fullimage.Properties.Gps?.Dictionary ?? new NSDictionary(), [ImageIO.CGImageProperties.IPTCDictionary] = fullimage.Properties.Iptc?.Dictionary ?? new NSDictionary(), [ImageIO.CGImageProperties.JFIFDictionary] = fullimage.Properties.Jfif?.Dictionary ?? new NSDictionary() }; } } catch (Exception ex) { Console.WriteLine(ex); } }); } return(meta, image.LocalIdentifier); }
void DeleteOriginal(NSUrl url) { var assets = PHAsset.FetchAssets(new NSUrl[] { url }, null); var asset = (PHAsset)assets.firstObject; var sharedLib = PHPhotoLibrary.SharedPhotoLibrary; sharedLib.PerformChanges(() => { var req = asset.CanPerformEditOperation(PHAssetEditOperation.Delete); if (req) { PHAssetChangeRequest.DeleteAssets(new PHAsset[] { asset }); } }, (success, err) => { if (success) { Debug.WriteLine("successfully deleted original"); } }); }
public Tuple <byte[], string, string> ReadFile(string file) { Tuple <byte[], string, string> result = null; var asset = PHAsset.FetchAssets(new[] { new NSUrl(file) }, null).LastObject as PHAsset; if (asset != null) { var options = new PHImageRequestOptions { Synchronous = true }; PHImageManager.DefaultManager.RequestImageData(asset, options, (data, dataUti, orientation, info) => { var extension = new NSUrl(dataUti).PathExtension; var uti = UTType.CreatePreferredIdentifier(UTType.TagClassFilenameExtension, extension, null); var mime = UTType.GetPreferredTag(uti, UTType.TagClassMIMEType); var dataBytes = new byte[data.Length]; Marshal.Copy(data.Bytes, dataBytes, 0, Convert.ToInt32(data.Length)); result = new Tuple <byte[], string, string>(dataBytes, dataUti, mime); }); } return(result); }
private void ChangeVideo(PHAsset asset, PHImageManager imageManager, PHVideoRequestOptions options) { DispatchQueue.DefaultGlobalQueue.DispatchAsync(() => imageManager?.RequestAvAsset(asset, options, (ass, mix, info) => DispatchQueue.MainQueue.DispatchAsync(() => { CurrentMediaType = MediaType.Video; _albumView.ImageCropView.Hidden = true; _albumView.MovieView.Hidden = false; var urlAsset = ass as AVUrlAsset; if (urlAsset == null) { return; } _albumView.MoviePlayerController.ContentUrl = urlAsset.Url; _albumView.MoviePlayerController.PrepareToPlay(); }))); }
private void CompleteTaskUsing(TaskCompletionSource <PlatformDocument> taskCompletionSource, UIImagePickerMediaPickedEventArgs args) { if (args.MediaUrl != null) { CompleteTaskUsing(taskCompletionSource, args); return; } try { string imageName = null; { var url = args.ReferenceUrl; if (url != null) { var assets = PHAsset.FetchAssets(new NSUrl[] { url }, null); if (assets.Count >= 1) { var asset = assets.firstObject as PHAsset; var dateFormatter = new NSDateFormatter() { DateFormat = "yyyy-MM-dd HH:mm:ss", }; imageName = dateFormatter.ToString(asset.CreationDate); } } } imageName = imageName ?? DateTime.UtcNow.ToString(); string path; using (var data = (args.OriginalImage as UIImage).AsJPEG()) { path = WriteToTemporaryFile(data); } taskCompletionSource.SetResult(new PlatformDocument(imageName + ".jpg", path)); } catch (Exception e) { taskCompletionSource.SetException(e); } }
private void ImagePicker_FinishedPickingMedia(object sender, UIImagePickerMediaPickedEventArgs e) { if (sender is UIImagePickerController picker) { string fileName = null; NSObject urlObj; if (e.Info.TryGetValue(UIImagePickerController.ReferenceUrl, out urlObj)) { var result = PHAsset.FetchAssets(new NSUrl[] { (urlObj as NSUrl) }, null); fileName = result?.firstObject?.ValueForKey(new NSString("filename"))?.ToString(); } fileName = fileName ?? $"photo_{DateTime.UtcNow.ToString("yyyyMMddHHmmss")}.jpg"; var lowerFilename = fileName?.ToLowerInvariant(); byte[] data; if (lowerFilename != null && (lowerFilename.EndsWith(".jpg") || lowerFilename.EndsWith(".jpeg"))) { using (var imageData = e.OriginalImage.AsJPEG()) { data = new byte[imageData.Length]; System.Runtime.InteropServices.Marshal.Copy(imageData.Bytes, data, 0, Convert.ToInt32(imageData.Length)); } } else { using (var imageData = e.OriginalImage.AsPNG()) { data = new byte[imageData.Length]; System.Runtime.InteropServices.Marshal.Copy(imageData.Bytes, data, 0, Convert.ToInt32(imageData.Length)); } } SelectFileResult(data, fileName); picker.DismissViewController(true, null); } }
public void LoadSampleStream(string filename, SerializationModel model) { try { string[] str = filename.Split('/'); PHFetchResult assetResult = PHAsset.FetchAssetsUsingLocalIdentifiers(str, null); PHAsset asset = assetResult.firstObject as PHAsset; Stream stream = new MemoryStream(); PHImageManager.DefaultManager.RequestImageData(asset, null, (data, dataUti, orientation, info) => { byte[] byteArray = data.ToArray(); Stream streamm = new MemoryStream(byteArray); dictionary.Add(filename, streamm); model.Location = filename; }); } catch (Exception) { } }
public void FetchResultIndex() { TestRuntime.AssertSystemVersion(PlatformName.iOS, 8, 0, throwIfOtherPlatform: false); if (ALAssetsLibrary.AuthorizationStatus != ALAuthorizationStatus.Authorized) { Assert.Inconclusive("Requires access to the photo library"); } var collection = PHAsset.FetchAssets(PHAssetMediaType.Image, null); if (collection.Count == 0) { XamagramImage.Image.SaveToPhotosAlbum(null); collection = PHAsset.FetchAssets(PHAssetMediaType.Image, null); } // Actual Test var obj = collection [0]; Assert.IsNotNull(obj); }
public void GetImage(PHAsset asset, CGSize size, PHImageRequestOptions options, Action<UIImage> action) { try { PHImageManager.DefaultManager.RequestImageForAsset(asset, size, PHImageContentMode.AspectFit, options, (image, info) => { try { action(image); } catch (Exception ex) { Console.WriteLine(ex); } }); } catch (Exception ex) { Console.WriteLine(ex); } }
public async Task <string> CreatePreviewPath(string path, string type) { await Task.Delay(TimeSpan.FromMilliseconds(100)); var fileName = System.IO.Path.GetFileNameWithoutExtension(path); var ext = System.IO.Path.GetExtension(path); var strs = path.Split('/'); var assetResult = PHAsset.FetchAssetsUsingLocalIdentifiers(strs, null); var asset = assetResult.firstObject as PHAsset; var thumbImageBytes = AssetImageService.GetImageBytes(asset, MediaFileGetImageOptions.CreateDefaultThumb()); var thumbnailImagePath = MediaFileHelper.GetOutputPath(MediaFileType.Image, "TmpMedia", $"{fileName}-THUMBNAIL{ext}"); System.IO.File.WriteAllBytes(thumbnailImagePath, thumbImageBytes); return(thumbnailImagePath); }
public void FetchResultObjectsAt() { TestRuntime.AssertSystemVersion(PlatformName.iOS, 8, 0, throwIfOtherPlatform: false); if (ALAssetsLibrary.AuthorizationStatus != ALAuthorizationStatus.Authorized) { Assert.Inconclusive("Requires access to the photo library"); } var collection = PHAsset.FetchAssets(PHAssetMediaType.Image, null); if (collection.Count == 0) { XamagramImage.Image.SaveToPhotosAlbum(null); collection = PHAsset.FetchAssets(PHAssetMediaType.Image, null); } // Actual Test var obj = collection.ObjectsAt <NSObject> (NSIndexSet.FromNSRange(new NSRange(0, 1))); Assert.That(obj != null && obj.Count() > 0); }
private async void SetGalleryButton() { var status = await PHPhotoLibrary.RequestAuthorizationAsync(); if (status == PHAuthorizationStatus.Authorized) { var options = new PHFetchOptions { SortDescriptors = new[] { new NSSortDescriptor("creationDate", false) }, FetchLimit = 5, }; var fetchedAssets = PHAsset.FetchAssets(PHAssetMediaType.Image, options); var lastGalleryPhoto = fetchedAssets.FirstOrDefault() as PHAsset; if (lastGalleryPhoto != null) { galleryButton.UserInteractionEnabled = true; var PHImageManager = new PHImageManager(); PHImageManager.RequestImageForAsset(lastGalleryPhoto, new CGSize(300, 300), PHImageContentMode.AspectFill, new PHImageRequestOptions() { DeliveryMode = PHImageRequestOptionsDeliveryMode.Opportunistic, ResizeMode = PHImageRequestOptionsResizeMode.Exact }, (img, info) => { galleryButton.Image = img; }); } else { galleryButton.UserInteractionEnabled = false; } } else { galleryButton.UserInteractionEnabled = true; } }
public void BindDataToCell(GalleryNative galleryDirectory, Action action) { var count = galleryDirectory.Images.Count; txtTitle.Text = galleryDirectory.Collection.LocalizedTitle; txtDescription.Text = "(" + count + ")"; imageView.ClipsToBounds = true; imageView.ContentMode = UIViewContentMode.ScaleAspectFill; try { var sortOptions = new PHFetchOptions(); sortOptions.SortDescriptors = new NSSortDescriptor[] { new NSSortDescriptor("creationDate", false) }; var items = PHAsset.FetchAssets(galleryDirectory.Collection, sortOptions).Cast <PHAsset>().ToList(); var options = new PHImageRequestOptions { Synchronous = true }; PHImageManager.DefaultManager.RequestImageForAsset(items[0], imageView.Bounds.Size, PHImageContentMode.AspectFit, options, (requestedImage, _) => { imageView.Image = requestedImage; }); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } if (ActionClick == null) { ActionClick = action; bttClick.TouchUpInside += (sender, e) => { ActionClick(); }; } }
public override void ViewDidLoad() { base.ViewDidLoad(); PHPhotoLibrary.RequestAuthorization((status) => { if (status == PHAuthorizationStatus.Authorized) { var result = PHAssetCollection.FetchTopLevelUserCollections(null); var assetCollection = result.firstObject as PHAssetCollection; var imageManager = new PHCachingImageManager(); var assets = PHAsset.FetchAssets(assetCollection, null); var imageAsset = assets[6]; this.InvokeOnMainThread(() => { imageManager.RequestImageForAsset((PHAsset)imageAsset, this.View.Frame.Size, PHImageContentMode.Default, null, new PHImageResultHandler(this.ImageReceived)); }); } }); }
private static string StorePickedImage(PHAsset asset, int quality, float scale, bool rotate, MediaFile tempMedia) { var tcs = new TaskCompletionSource <string>(); var task = tcs.Task; var imageManager = PHImageManager.DefaultManager; using (var requestOptions = new PHImageRequestOptions { Synchronous = true, NetworkAccessAllowed = true, DeliveryMode = PHImageRequestOptionsDeliveryMode.HighQualityFormat, }) { imageManager.RequestImageData(asset, requestOptions, (data, dataUti, orientation, info) => { Task.Factory.StartNew(() => { StoreImageData(asset, quality, scale, rotate, tempMedia, info, data, tcs); }); }); } return(task.Result); }
private void OnAuthorized() { DispatchQueue.MainQueue.DispatchAsync(() => { _imageManager = new PHCachingImageManager(); var options = new PHFetchOptions { SortDescriptors = new[] { new NSSortDescriptor("creationDate", false) } }; var assets = new List <PHAsset>(); if (_mediaTypes.HasFlag(MediaType.Image)) { _images = PHAsset.FetchAssets(PHAssetMediaType.Image, options); assets.AddRange(_images.OfType <PHAsset>()); } if (_mediaTypes.HasFlag(MediaType.Video)) { _videos = PHAsset.FetchAssets(PHAssetMediaType.Video, options); assets.AddRange(_videos.OfType <PHAsset>()); } foreach (var asset in assets.OrderByDescending(a => a.CreationDate.SecondsSinceReferenceDate)) { AllAssets.Add(asset); } ShowFirstImage(); AllAssets.CollectionChanged += AssetsCollectionChanged; PHPhotoLibrary.SharedPhotoLibrary.RegisterChangeObserver(this); }); }
internal MultiAssetEventArgs(PHAsset[] assets) { Assets = assets; }
public void Bind (PHAsset asset) { this.Asset = asset; if (Asset.MediaType == PHAssetMediaType.Video) { _videoIcon.Hidden = false; _videoDuration.Hidden = false; _gradientView.Hidden = false; _videoDuration.Text = GetDurationWithFormat (Asset.Duration); } else { _videoIcon.Hidden = true; _videoDuration.Hidden = true; _gradientView.Hidden = true; } }
internal SingleAssetEventArgs (PHAsset asset) { Asset = asset; }
internal CancellableAssetEventArgs(PHAsset asset) : base (asset) { }
CGSize getScaledSizeForAsset (PHAsset asset, bool scaleSize) { var size = new CGSize (asset.PixelWidth, asset.PixelHeight); var scaled = standardSize.Height / size.Height; if (scaleSize) scaled *= UIScreen.MainScreen.Scale; return CGAffineTransform.MakeScale(scaled, scaled).TransformSize(size); }
private void UpdateImage(PHAsset asset) { // UIView.Animate(1, 0, UIViewAnimationOptions.TransitionCurlUp, () => _imageView.Image = img, ()=>{}); PHImageManager.DefaultManager.RequestImageForAsset(asset, View.Frame.Size, PHImageContentMode.AspectFit, new PHImageRequestOptions(), (image, info) => ReplaseImage(image)); }
public ImageModel(PHAsset asset, PHCachingImageManager manager) { ImageAsset = asset; ImageManager = manager; }
internal bool VerifyShouldSelectAsset(PHAsset asset) { return VerifyCancellableAssetEventHandler (asset, ShouldSelectAsset); }
internal void NotifyAssetUnhighlighted(PHAsset asset) { var e = AssetUnhighlighted; if (e != null) { e (this, new SingleAssetEventArgs (asset)); } }
public void DeselectAsset (PHAsset asset) { _selectedAssets.Remove (asset); if (!_selectedAssets.Any ()) { UpdateDoneButton (); } if (DisplaySelectionInfoToolbar || ShowCameraButton) { UpdateToolbar (); } }
/// <summary> /// Adds one asset to the selection and updates the UI. /// </summary> public void SelectAsset (PHAsset asset) { if (!_selectedAssets.Exists(a => a.LocalIdentifier == asset.LocalIdentifier)) { _selectedAssets.Add (asset); UpdateDoneButton (); if (!AllowsMultipleSelection) { if (ConfirmSingleSelection) { var message = ConfirmSingleSelectionPrompt ?? "picker.confirm.message".Translate (defaultValue: "Do you want to select the image you tapped on?"); var alert = UIAlertController.Create ("picker.confirm.title".Translate (defaultValue: "Are you sure?"), message, UIAlertControllerStyle.Alert); alert.AddAction (UIAlertAction.Create ("picker.action.no".Translate (defaultValue: "No"), UIAlertActionStyle.Cancel, null)); alert.AddAction (UIAlertAction.Create ("picker.action.yes".Translate (defaultValue: "Yes"), UIAlertActionStyle.Default, action => { FinishPickingAssets (this, EventArgs.Empty); })); PresentViewController (alert, true, null); } else { FinishPickingAssets (this, EventArgs.Empty); } } else if (DisplaySelectionInfoToolbar || ShowCameraButton) { UpdateToolbar (); } } }
private UIImage GetImage(PHAsset asset) { UIImage result = null; var options = new PHImageRequestOptions { Synchronous = true, }; var size = new CGSize(asset.PixelWidth, asset.PixelHeight); PHImageManager.DefaultManager.RequestImageForAsset(asset, size, PHImageContentMode.AspectFit, options, (image, info) => result = image); return result; }
private bool VerifyCancellableAssetEventHandler(PHAsset asset, CancellableAssetEventHandler del, bool defaultValue = true) { var result = defaultValue; var e = del; if (e != null) { var args = new CancellableAssetEventArgs (asset); e (this, args); result = !args.Cancel; } return result; }
PHAsset[] AssetsAtIndexPaths (Array indexPaths) { if (indexPaths.Length == 0) return null; var assets = new PHAsset[indexPaths.Length]; for (int i = 0; i < indexPaths.Length; i++) { var asset = (PHAsset)AssetsFetchResults.ObjectAt (i); assets [i] = asset; } return assets; }
private ImageEntity CreateImage(PHAsset asset) { try { var result = new ImageEntity { LocalIdentifier = asset.LocalIdentifier, CreateTime = asset.CreationDate.ToDateTime() }; return result; } catch (Exception ex) { Console.WriteLine(ex); return new ImageEntity { LocalIdentifier = asset.LocalIdentifier, CreateTime = DateTime.MinValue }; } }
private void UpdateImage(PHAsset asset) { var options = new PHImageRequestOptions { Synchronous = true, }; var size = new CGSize(asset.PixelWidth, asset.PixelHeight); PHImageManager.DefaultManager.RequestImageForAsset(asset, size, PHImageContentMode.AspectFit, options, (image, info) => ReplaseImage(image)); }