// When user picks a photo, add it to TextView void PhotoViewController_ImageSelected(object sender, PhotoEventArgs e) { var image = e.Image; // Get the location where we are going to insert the image var cursorLocation = TxtContent.SelectedRange.Location; // Resize the image if it's to big, to display it nicely in TextView nfloat sideLimit = UIScreen.MainScreen.Bounds.Width - 10; if (!VerifyImageSides(image, sideLimit)) { image = ResizeImage(image, sideLimit); } // Save image location to update it if user types more text later. Note.ImagesInfo.Add(new ImageInfo { Id = e.ImageId, Location = cursorLocation }); // Save the image in Firebase Storage SaveImageToStorage(e.ImageId, e.Image); // Save image in disk to load it in TextView more quickly SaveImageToDisk(e.ImageId, e.Image); // Insert image in TextView, adding 1 to text length InsertImageInText(TxtContent, e.ImageId, image, cursorLocation, false); // If text have an image after this location, we need to add 1 to their locations // because we have just inserted 1 char to text UpdateImagesLocation(cursorLocation, 1); }
public override void ItemSelected(UICollectionView collectionView, NSIndexPath indexPath) { var cell = collectionView.CellForItem(indexPath) as PhotoCell; if (cell != null) { var asset = images [indexPath.Item] as PHAsset; imageManager.RequestImageForAsset(asset, PHImageManager.MaximumSize, PHImageContentMode.AspectFill, null, (result, info) => { var args = new PhotoEventArgs { Image = result, ImageId = AppDelegate.GetUtcTimestamp().ToString() }; ImageSelected?.Invoke(this, args); DismissViewController(true, null); }); } else { RequestAccessToPhotoLibrary(); } }