Пример #1
0
        private void OnImagePickerFinishedPickingMedia(object sender, UIImagePickerMediaPickedEventArgs args)
        {
            string  targetPath = null;
            UIImage image      = args.EditedImage ?? args.OriginalImage;

            if (image != null)
            {
                // Convert UIImage to .NET Stream object
                NSData data = image.AsJPEG(1);
                using (System.IO.Stream stream = data.AsStream())
                {
                    string extension = ".jpg";

                    string fullFileName = FileNameWithoutExtension + extension;
                    targetPath = System.IO.Path.Combine(CopyToDirectory, fullFileName);

                    // copy the file to the destination and set the completion of the Task
                    using (var copiedFileStream = new System.IO.FileStream(targetPath, System.IO.FileMode.OpenOrCreate))
                    {
                        stream.CopyTo(copiedFileStream);
                    }
                    TaskCompletionSource.SetResult(fullFileName); // we'll reconstruct the path at runtime
                }
            }
            else
            {
                TaskCompletionSource.SetResult(null);
            }
            ImagePicker.DismissViewController(true, null);
        }
Пример #2
0
 private void OnImagePickerCancelled(object sender, EventArgs args)
 {
     TaskCompletionSource.SetResult(null);
     ImagePicker.DismissViewController(true, null);
 }