private async Task <MediaFile> GetPictureMediaFile(NSDictionary info) { var image = (UIImage)info[UIImagePickerController.EditedImage]; if (image == null) { image = (UIImage)info[UIImagePickerController.OriginalImage]; } var meta = info[UIImagePickerController.MediaMetadata] as NSDictionary; string path = GetOutputPath(MediaImplementation.TypeImage, options.Directory ?? ((IsCaptured) ? String.Empty : "temp"), options.Name); using (FileStream fs = File.OpenWrite(path)) using (Stream s = new NSDataStream(image.AsJPEG())) { s.CopyTo(fs); fs.Flush(); } Action <bool> dispose = null; string aPath = null; if (source != UIImagePickerControllerSourceType.Camera) { dispose = d => File.Delete(path); } else { if (this.options.SaveToAlbum) { try { var library = new ALAssetsLibrary(); var albumSave = await library.WriteImageToSavedPhotosAlbumAsync(image.CGImage, meta); aPath = albumSave.AbsoluteString; } catch (Exception ex) { Console.WriteLine("unable to save to album:" + ex); } } } return(new MediaFile(path, () => File.OpenRead(path), dispose: dispose, albumPath: aPath)); }
private async Task<MediaFile> GetPictureMediaFile(NSDictionary info) { var image = (UIImage)info[UIImagePickerController.EditedImage]; if (image == null) image = (UIImage)info[UIImagePickerController.OriginalImage]; var meta = info[UIImagePickerController.MediaMetadata] as NSDictionary; string path = GetOutputPath(MediaImplementation.TypeImage, options.Directory ?? ((IsCaptured) ? String.Empty : "temp"), options.Name); using (FileStream fs = File.OpenWrite(path)) using (Stream s = new NSDataStream(image.AsJPEG())) { s.CopyTo(fs); fs.Flush(); } Action<bool> dispose = null; string aPath = null; if (source != UIImagePickerControllerSourceType.Camera) dispose = d => File.Delete(path); else { if (this.options.SaveToAlbum) { try { var library = new ALAssetsLibrary(); var albumSave = await library.WriteImageToSavedPhotosAlbumAsync(image.CGImage, meta); aPath = albumSave.AbsoluteString; } catch (Exception ex) { Console.WriteLine("unable to save to album:" + ex); } } } return new MediaFile(path, () => File.OpenRead(path), dispose: dispose, albumPath: aPath); }
private MediaFile GetPictureMediaFile(NSDictionary info) { var image = (UIImage)info[UIImagePickerController.EditedImage]; if (image == null) image = (UIImage)info[UIImagePickerController.OriginalImage]; string path = GetOutputPath(MediaImplementation.TypeImage, options.Directory ?? ((IsCaptured) ? String.Empty : "temp"), options.Name); using (FileStream fs = File.OpenWrite(path)) using (Stream s = new NSDataStream(image.AsJPEG())) { s.CopyTo(fs); fs.Flush(); } Action<bool> dispose = null; if (this.source != UIImagePickerControllerSourceType.Camera) dispose = d => File.Delete(path); return new MediaFile(path, () => File.OpenRead(path), dispose: dispose); }