void ShowPicker (UIImagePickerControllerSourceType sourceType) { if (!UIImagePickerController.IsSourceTypeAvailable (sourceType)) { var alert = new UIAlertView ("Image Picker", "Source type not available", null, "Close"); alert.Show (); } else { _controller._picker.SourceType = sourceType; string[] availableMediaTypes = UIImagePickerController.AvailableMediaTypes (sourceType); string[] requestedMediaTypes = new string[] { "public.image", "public.movie" }; List<string> mediaTypes = new List<string> (); foreach (string mediaType in requestedMediaTypes) { if (availableMediaTypes.Contains (mediaType)) mediaTypes.Add (mediaType); } _controller._picker.MediaTypes = mediaTypes.ToArray (); _controller.PresentModalViewController (_controller._picker, true); } }
public static Task <UIImage> ShowMediaPicker(this UIViewController vc, UIImagePickerControllerSourceType sourceType, bool allowEditing = true) { var tcs = new TaskCompletionSource <UIImage>(); var picker = new UIImagePickerController { SourceType = sourceType, MediaTypes = UIImagePickerController.AvailableMediaTypes(sourceType), AllowsEditing = allowEditing }; picker.FinishedPickingMedia += (sender, e) => { var image = e.EditedImage ?? e.OriginalImage; picker.DismissViewController(true, null); tcs.SetResult(image); }; picker.Canceled += (sender, e) => tcs.SetResult(null); vc.PresentViewController(picker, true, null); return(tcs.Task); }
/// <summary> /// Setups the controller. /// </summary> /// <param name="mpDelegate">The mp delegate.</param> /// <param name="sourceType">Type of the source.</param> /// <param name="mediaType">Type of the media.</param> /// <param name="options">The options.</param> /// <returns>MediaPickerController.</returns> private static MediaPickerController SetupController( MediaPickerDelegate mpDelegate, UIImagePickerControllerSourceType sourceType, string mediaType, MediaStorageOptions options = null) { var picker = new MediaPickerController(mpDelegate) { MediaTypes = new[] { mediaType }, SourceType = sourceType }; if (sourceType == UIImagePickerControllerSourceType.Camera) { if (mediaType == TypeImage && options is CameraMediaStorageOptions) { picker.CameraDevice = GetCameraDevice(((CameraMediaStorageOptions)options).DefaultCamera); picker.CameraCaptureMode = UIImagePickerControllerCameraCaptureMode.Photo; } else if (mediaType == TypeMovie && options is VideoMediaStorageOptions) { var voptions = (VideoMediaStorageOptions)options; picker.CameraDevice = GetCameraDevice(voptions.DefaultCamera); picker.CameraCaptureMode = UIImagePickerControllerCameraCaptureMode.Video; picker.VideoQuality = GetQuailty(voptions.Quality); picker.VideoMaximumDuration = voptions.DesiredLength.TotalSeconds; } } return(picker); }
/// <summary> /// Setups the controller. /// </summary> /// <param name="mediaDelegate">The media picker delegate.</param> /// <param name="sourceType">Media source type.</param> /// <param name="mediaType">Media type.</param> /// <param name="options">The options.</param> /// <returns>The configured media picker controller.</returns> private static MediaPickerController SetupController( MediaPickerDelegate mediaDelegate, UIImagePickerControllerSourceType sourceType, string mediaType, CameraMediaStorageOptions options = null) { // Create the media picker var picker = new MediaPickerController(mediaDelegate) { MediaTypes = new[] { mediaType }, SourceType = sourceType }; // If the image is from camera if (sourceType == UIImagePickerControllerSourceType.Camera) { if ((mediaType == MediaPickerIOS.TypeImage) && (options != null)) { // Configure the camera picker.CameraDevice = MediaPickerIOS.GetCameraDevice(options.DefaultCamera); picker.CameraCaptureMode = UIImagePickerControllerCameraCaptureMode.Photo; } } return(picker); }
void ShowPicker(UIImagePickerControllerSourceType sourceType) { if (!UIImagePickerController.IsSourceTypeAvailable(sourceType)) { var alert = new UIAlertView("Image Picker", "Source type not available", null, "Close"); alert.Show(); } else { _controller._picker.SourceType = sourceType; string[] availableMediaTypes = UIImagePickerController.AvailableMediaTypes(sourceType); string[] requestedMediaTypes = new string[] { "public.image", "public.movie" }; List <string> mediaTypes = new List <string> (); foreach (string mediaType in requestedMediaTypes) { if (availableMediaTypes.Contains(mediaType)) { mediaTypes.Add(mediaType); } } _controller._picker.MediaTypes = mediaTypes.ToArray(); _controller.PresentModalViewController(_controller._picker, true); } }
protected void WriteImage (string path, int size, Action<bool> callback, UIImagePickerControllerSourceType sourceType, string[] mediaTypes) { Present (sourceType , mediaTypes , data => { if(data == null) callback(false); else { if (File.Exists (path)) { _questionDialog = new UIAlertView (D.WARNING, D.FILENAME_EXISTS_REPLACE, null, D.YES, D.NO); _questionDialog.Clicked += (object sender, UIButtonEventArgs e) => { if (e.ButtonIndex == 0) { try { File.Delete (path); } catch (IOException) { callback (false); return; } Save (path, size, callback, data); } else callback (false); }; _questionDialog.Show (); } else { string dir = Path.GetDirectoryName (path); if (!Directory.Exists (dir)) Directory.CreateDirectory (dir); Save (path, size, callback, data); } } }); }
private static MediaPickerController SetupController(MediaPickerDelegate mpDelegate, UIImagePickerControllerSourceType sourceType, String mediaType, StoreCameraMediaOptions options = null) { var picker = new MediaPickerController(mpDelegate); picker.MediaTypes = new[] { mediaType }; picker.SourceType = sourceType; if (sourceType == UIImagePickerControllerSourceType.Camera) { picker.CameraDevice = GetUICameraDevice(options.DefaultCamera); if (mediaType == TypeImage) { picker.CameraCaptureMode = UIImagePickerControllerCameraCaptureMode.Photo; } else if (mediaType == TypeMovie) { StoreVideoOptions voptions = (StoreVideoOptions)options; picker.CameraCaptureMode = UIImagePickerControllerCameraCaptureMode.Video; picker.VideoQuality = GetQuailty(voptions.Quality); picker.VideoMaximumDuration = voptions.DesiredLength.TotalSeconds; } } return(picker); }
private async Task <Stream> GetImageStream(UIImagePickerControllerSourceType sourceType) { if (!UIImagePickerController.IsSourceTypeAvailable(sourceType)) { throw new NotSupportedException("{sourceType} source is not available"); } var tcs = new TaskCompletionSource <UIImage>(); var picker = new UIImagePickerController() { Delegate = new ImagePickerControllerDelegate(tcs), SourceType = sourceType }; var rootController = UIApplication.SharedApplication.KeyWindow?.RootViewController; rootController?.PresentViewController(picker, true, null); var pickedImage = await tcs.Task; if (pickedImage == null) { return(null); } var imageData = pickedImage.AsJPEG(1); var imageStream = imageData.AsStream(); return(imageStream); }
private void AddButtonToMediaSourceTypePickerIfTypeAvailable(string buttonLabel, UIImagePickerControllerSourceType mediaSourceType) { if (IsPickerTypeAvailable(mediaSourceType)) { mediaSourceTypePicker.AddButton(buttonLabel); lastAddedMediaSourceTypeButtonIndex += 1; buttonIndexesForMediaSourceTypes.Add(lastAddedMediaSourceTypeButtonIndex, mediaSourceType); } }
Task <List <MediaFile> > GetMediasAsync(UIImagePickerControllerSourceType sourceType, string mediaType, StoreCameraMediaOptions options = null, MultiPickerOptions pickerOptions = null, CancellationToken token = default(CancellationToken)) { var viewController = GetHostViewController(); if (options == null) { options = new StoreCameraMediaOptions(); } var ndelegate = new MediaPickerDelegate(viewController, sourceType, options, token); var od = Interlocked.CompareExchange(ref pickerDelegate, ndelegate, null); if (od != null) { throw new InvalidOperationException("Only one operation can be active at a time"); } var picker = ELCImagePickerViewController.Create(options, pickerOptions); if (UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad && sourceType == UIImagePickerControllerSourceType.PhotoLibrary) { ndelegate.Popover = popover = new UIPopoverController(picker); ndelegate.Popover.Delegate = new MediaPickerPopoverDelegate(ndelegate, picker); ndelegate.DisplayPopover(); } else { if (UIDevice.CurrentDevice.CheckSystemVersion(9, 0)) { picker.ModalPresentationStyle = UIModalPresentationStyle.OverCurrentContext; } viewController.PresentViewController(picker, true, null); } // TODO: Make this use the existing Delegate? return(picker.Completion.ContinueWith(t => { Dismiss(popover, picker); picker.BeginInvokeOnMainThread(() => { picker.DismissViewController(true, null); }); if (t.IsCanceled || t.Exception != null) { return Task.FromResult(new List <MediaFile>()); } var files = t.Result; Parallel.ForEach(files, mediaFile => { ResizeAndCompressImage(options, mediaFile, Path.GetExtension(mediaFile.Path).Replace(".", string.Empty)); }); return t; }).Unwrap()); }
void Pick(UIImagePickerControllerSourceType type) { if (UIImagePickerController.IsSourceTypeAvailable(type)) { picker = new UIImagePickerController(); picker.Delegate = new CameraDelegate(this); picker.SourceType = type; picker.MediaTypes = new string[] { UTType.Image }; NavigationController.PresentViewController(picker, true, null); } }
void StartPhotoPicker(UIImagePickerControllerSourceType type) { _imagePicker = new UIImagePickerController(); _imagePicker.SourceType = type; _imagePicker.MediaTypes = UIImagePickerController.AvailableMediaTypes(UIImagePickerControllerSourceType.PhotoLibrary); _imagePicker.FinishedPickingMedia += FinishedPickingMediaHandler; _imagePicker.Canceled += CancelationHandler; NavigationController.PresentModalViewController(_imagePicker, true); }
void Present (UIImagePickerControllerSourceType sourceType, string[] mediaTypes, Action<NSDictionary> onPick) { _imagePicker = new UIImagePickerController (); _imagePicker.SourceType = sourceType; if (mediaTypes != null) _imagePicker.MediaTypes = mediaTypes; _imagePicker.Delegate = new ImagePickerDelegate (onPick); _controller.PresentViewController (_imagePicker, true, null); }
internal MediaPickerDelegate (UIViewController viewController, UIImagePickerControllerSourceType sourceType, StoreCameraMediaOptions options) { this.viewController = viewController; this.source = sourceType; this.options = options ?? new StoreCameraMediaOptions(); if (viewController != null) { UIDevice.CurrentDevice.BeginGeneratingDeviceOrientationNotifications(); this.observer = NSNotificationCenter.DefaultCenter.AddObserver (UIDevice.OrientationDidChangeNotification, DidRotate); } }
internal PickerDelegate(UIViewController viewController, UIImagePickerControllerSourceType sourceType) { Controller = viewController; Source = sourceType; if (Controller != null) { IsPickerDisposed = false; UIDevice.CurrentDevice.BeginGeneratingDeviceOrientationNotifications(); OrientationObserver = NSNotificationCenter.DefaultCenter.AddObserver(UIDevice.OrientationDidChangeNotification, DidRotate); } }
internal MediaPickerDelegate(UIViewController viewController, UIImagePickerControllerSourceType sourceType, StoreCameraMediaOptions options) { this.viewController = viewController; source = sourceType; this.options = options ?? new StoreCameraMediaOptions(); if (viewController != null) { UIDevice.CurrentDevice.BeginGeneratingDeviceOrientationNotifications(); observer = NSNotificationCenter.DefaultCenter.AddObserver(UIDevice.OrientationDidChangeNotification, DidRotate); } }
private void ShowImagePicker(UIImagePickerControllerSourceType sourceType) { if (this.ImageView.IsAnimating) { this.ImageView.StopAnimating(); } if (UIImagePickerController.IsSourceTypeAvailable(sourceType)) { this.SetupImagePicker(sourceType); this.PresentViewController(imagePickerController, true, null); } }
void Present(UIImagePickerControllerSourceType sourceType, string[] mediaTypes, Action <NSDictionary> onPick) { _imagePicker = new UIImagePickerController(); _imagePicker.SourceType = sourceType; if (mediaTypes != null) { _imagePicker.MediaTypes = mediaTypes; } _imagePicker.Delegate = new ImagePickerDelegate(onPick); _controller.PresentViewController(_imagePicker, true, null); }
private Task <MediaFile> GetMediaAsync(UIImagePickerControllerSourceType sourceType, string mediaType, StoreCameraMediaOptions options = null) { var viewController = FindRootViewController(); var ndelegate = new MediaPickerDelegate(viewController, sourceType, options); var od = Interlocked.CompareExchange(ref pickerDelegate, ndelegate, null); if (od != null) { throw new InvalidOperationException("Only one operation can be active at at time"); } MediaPickerController picker; if (mediaType == TypeAll) { picker = SetupCameraController(ndelegate, (StoreVideoOptions)options); } else { picker = SetupController(ndelegate, sourceType, mediaType, options); } if (UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad && sourceType == UIImagePickerControllerSourceType.PhotoLibrary) { ndelegate.Popover = popover = new UIPopoverController(picker); ndelegate.Popover.Delegate = new MediaPickerPopoverDelegate(ndelegate, picker); ndelegate.DisplayPopover(); } else { if (UIDevice.CurrentDevice.CheckSystemVersion(9, 0)) { picker.ModalPresentationStyle = UIModalPresentationStyle.FullScreen; } viewController.PresentViewController(picker, true, null); } return(ndelegate.Task.ContinueWith(t => { if (popover != null) { popover.Dispose(); popover = null; } Interlocked.Exchange(ref pickerDelegate, null); picker.Dispose(); return t; }).Unwrap()); }
static UIImagePickerController CreateController(PickerDelegate mpDelegate, UIImagePickerControllerSourceType sourceType, string mediaType, MediaCaptureSettings settings) { var picker = new UIImagePickerController { Delegate = mpDelegate, MediaTypes = new[] { mediaType }, SourceType = sourceType }; if (sourceType != UIImagePickerControllerSourceType.Camera) { return(picker); } if (settings.Camera == CameraOption.Front) { picker.CameraDevice = UIImagePickerControllerCameraDevice.Front; } picker.AllowsEditing = settings.AllowEditing; if (settings.OverlayViewProvider != null) { var overlay = settings.OverlayViewProvider(); if (overlay is UIView) { picker.CameraOverlayView = overlay as UIView; } } if (mediaType == VIDEO_TYPE) { if (settings.VideoMaxDuration.HasValue) { picker.VideoMaximumDuration = settings.VideoMaxDuration.Value.TotalSeconds; } picker.CameraCaptureMode = UIImagePickerControllerCameraCaptureMode.Video; switch (settings.VideoQuality) { case VideoQuality.Medium: picker.VideoQuality = UIImagePickerControllerQualityType.Medium; break; case VideoQuality.Low: picker.VideoQuality = UIImagePickerControllerQualityType.Low; break; default: picker.VideoQuality = UIImagePickerControllerQualityType.High; break; } } return(picker); }
private async Task <byte[]> SelectMediaAsync(UIImagePickerControllerSourceType sourceType) { _imageTask = new TaskCompletionSource <byte[]>(); _imagePicker = new UIImagePickerController(); _imagePicker.PrefersStatusBarHidden(); _imagePicker.SourceType = sourceType; _imagePicker.FinishedPickingMedia += OnCaptureComplete; _imagePicker.Canceled += OnCaptureCancelled; StartCapture(); var imageBytes = await _imageTask.Task; return(imageBytes); }
protected void WriteImage(string path, int size, Action <bool> callback, UIImagePickerControllerSourceType sourceType, string[] mediaTypes) { Present(sourceType , mediaTypes , data => { if (data == null) { callback(false); } else { if (IOContext.Current.Exists(path, FileSystemItem.File)) { _questionDialog = new UIAlertView(D.WARNING, D.FILENAME_EXISTS_REPLACE, null, D.YES, D.NO); _questionDialog.Clicked += (sender, e) => { if (e.ButtonIndex == 0) { try { IOContext.Current.Delete(path); } catch (IOException) { callback(false); return; } Save(path, size, callback, data); } else { callback(false); } }; _questionDialog.Show(); } else { string dir = Path.GetDirectoryName(path); IOContext.Current.CreateDirectory(dir); Save(path, size, callback, data); } } }); }
private static void PickImageInternal(UIViewController parent, UIImagePickerControllerSourceType source, Action <UIImage> callback) { var imagePicker = new UIImagePickerController { AllowsEditing = AllowEditing, AllowsImageEditing = AllowImageEditing }; imagePicker.FinishedPickingMedia += (sender, e) => { imagePicker.DismissViewController(true, () => callback?.Invoke(e.OriginalImage)); }; imagePicker.SourceType = source; imagePicker.MediaTypes = UIImagePickerController.AvailableMediaTypes(source); imagePicker.Canceled += (sender, e) => imagePicker.DismissViewController(true, null); parent.PresentViewController(imagePicker, true, null); }
/// <summary> /// Shows the image picker. /// </summary> public static void ShowImagePicker(UIImagePickerControllerSourceType source = UIImagePickerControllerSourceType.PhotoLibrary, UIImagePickerControllerCameraDevice cameraDevice = UIImagePickerControllerCameraDevice.Rear) { _picker = new UIImagePickerController(); // _picker.AllowsEditing = true; _picker.sourceType = source; // _picker.Delegate = ImagePickerControllerDelegate.instance; _picker.DidFinishPickingMediaWithInfo += _OnPickedMedia; _picker.DidCancel += _OnCancelledPick; if (source == UIImagePickerControllerSourceType.Camera) { _picker.cameraDevice = cameraDevice; } var rootVc = UIApplication.deviceRootViewController; if (CoreXT.IsiPad && (source != UIImagePickerControllerSourceType.Camera)) { if (_popover == null) { _popover = new UIPopoverController(_picker); _popover.DidDismiss += _OnCancelledPick; _popover.shouldDismissHandler = _ShouldDismissPopover; } else { _popover.contentViewController = _picker; } var rect = rootVc.view.bounds; rect.x = rect.width / 2; rect.y = rect.height; rect.width = 1; rect.height = 1; _popover.PresentPopover( rect, rootVc.view, UIPopoverArrowDirection.Down, true); } else { rootVc.PresentViewController(_picker, true, null); } }
/// <summary> /// Presents an image picker. /// </summary> /// <param name="sourceType">The picker source.</param> /// <param name="cameraPosition">The position for the camera if the camera is used.</param> /// <param name="actionComplete">An action that will get invoked when complete.</param> /// <param name="actionCanceled">An action that will get invoked when canceled.</param> protected void PresentImagePicker(UIImagePickerControllerSourceType sourceType, CameraPosition?cameraPosition, Action <byte[]> actionComplete, Action actionCanceled) { UIViewController presentingController = this.getPresentingController(); UIImagePickerController imagePickerController = new UIImagePickerController(); imagePickerController.AllowsEditing = true; imagePickerController.SourceType = sourceType; if (cameraPosition == CameraPosition.Front) { imagePickerController.CameraDevice = UIImagePickerControllerCameraDevice.Front; } imagePickerController.FinishedPickingMedia += (sender, e) => this.HandleFinishedFinishedPickingMedia(imagePickerController, e, actionComplete); imagePickerController.Canceled += (sender, e) => this.HandleCanceled(imagePickerController, actionCanceled); presentingController.PresentViewController(imagePickerController, true, () => { }); }
/// <summary> /// Initializes a new instance of the <see cref="MediaPickerDelegate"/> class. /// </summary> /// <param name="viewController">The view controller.</param> /// <param name="sourceType">Type of the source.</param> /// <param name="options">The options.</param> internal MediaPickerDelegate( UIViewController viewController, UIImagePickerControllerSourceType sourceType, CameraMediaStorageOptions options) { // Setup the current media picker delegate this.viewController = viewController; this.source = sourceType; this.options = options ?? new CameraMediaStorageOptions(); // Add the observer if (viewController != null) { UIDevice.CurrentDevice.BeginGeneratingDeviceOrientationNotifications(); this.observer = NSNotificationCenter.DefaultCenter.AddObserver( UIDevice.OrientationDidChangeNotification, this.DidRotate); } }
private async Task <ImagePickerResult?> GetImageAsync(UIImagePickerControllerSourceType type, float quality) { _pickerController = new UIImagePickerController { SourceType = type, MediaTypes = new string[] { UTType.Image }, }; _pickerController.FinishedPickingMedia += OnFinishedPickingMedia; _pickerController.Canceled += OnCanceled; _taskCompletionSource = new TaskCompletionSource <UIImage?>(); UIApplication.SharedApplication.KeyWindow.RootViewController.PresentViewController(_pickerController, true, null); var image = await _taskCompletionSource.Task.ConfigureAwait(false); return(new IosImagePickerResult { ImageObject = image, Quality = quality, ImageExtension = ImageExtension.Jpeg }); }
/// <summary> /// Creates the UIImagePickerController picker in either camera or photo mode. /// Throws an ArgumentException if <see cref="sourceType"/> is neither "camera" nor "photo". /// </summary> /// /// <param name="mode">The source of UIImagePickerController.</param> private void CreateImagePicker(UIImagePickerControllerSourceType sourceType) { imagePicker = new UIImagePickerController(); imagePicker.Delegate = this; NavigationControllerUtil.SetNavigationBarAttributes(imagePicker.NavigationBar); if (sourceType == UIImagePickerControllerSourceType.Camera) { // set our source to the camera imagePicker.SourceType = sourceType; // open camera in photo mode only imagePicker.CameraCaptureMode = UIImagePickerControllerCameraCaptureMode.Photo; } else if (sourceType == UIImagePickerControllerSourceType.PhotoLibrary) { // Set our source to the photo library // The 'availableMediaTypes' property determines the types of media presented in the interface. // By default, this is set to the single value kUTTypeImage, which specifies that only // still images should be displayed in the media picker when browsing saved media. // See https://developer.apple.com/documentation/uikit/uiimagepickercontroller/1619173-mediatypes imagePicker.SourceType = sourceType; } else { // should never enter this throw new ArgumentException("Invalid UIIMagePickerControlerSourceType."); } AnalyticsService.TrackEvent(AnalyticsService.Event.ImagePickerSelected, new Dictionary <string, string> { { AnalyticsService.PropertyKey.Method, imagePicker.SourceType.ToString() } }); // Set handlers imagePicker.FinishedPickingMedia += Handle_FinishedPickingMedia; imagePicker.Canceled += Handle_Canceled; }
static async Task <FileInfo> DoLaunchMediaPicker(UIImagePickerControllerSourceType sourceType, string mediaType, MediaCaptureSettings settings) { Log.For(typeof(Media)).Warning("DoLaunchMediaPicker called"); var controller = UIRuntime.Window.RootViewController; while (controller.PresentedViewController != null) { controller = controller.PresentedViewController; } var pickerDelegate = new PickerDelegate(controller, sourceType); var picker = CreateController(pickerDelegate, sourceType, mediaType, settings); var usePopup = UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad && sourceType == UIImagePickerControllerSourceType.PhotoLibrary; if (usePopup) { pickerDelegate.Popover = new UIPopoverController(picker) { Delegate = new PickerPopoverDelegate(pickerDelegate, picker) }; pickerDelegate.DisplayPopover(); } else { if (OS.IsAtLeastiOS(9)) { picker.ModalPresentationStyle = UIModalPresentationStyle.OverCurrentContext; } controller.PresentViewController(picker, animated: true, completionHandler: null); } return(await pickerDelegate.CompletionSource.Task.ConfigureAwait(false)); }
static MediaPickerController SetupController(MediaPickerDelegate mpDelegate, UIImagePickerControllerSourceType sourceType, string mediaType, TaskCompletionSource <Task> taskCompletionSource, StoreCameraMediaOptions options = null) { var picker = new MediaPickerController(mpDelegate, taskCompletionSource); picker.MediaTypes = new[] { mediaType }; picker.SourceType = sourceType; if (sourceType == UIImagePickerControllerSourceType.Camera) { picker.CameraDevice = GetUICameraDevice(options.DefaultCamera); picker.AllowsEditing = options?.AllowCropping ?? false; if (options.OverlayViewProvider != null) { var overlay = options.OverlayViewProvider(); if (overlay is UIView) { picker.CameraOverlayView = overlay as UIView; } } if (mediaType == TypeImage) { picker.CameraCaptureMode = UIImagePickerControllerCameraCaptureMode.Photo; } else if (mediaType == TypeMovie) { var voptions = (StoreVideoOptions)options; picker.CameraCaptureMode = UIImagePickerControllerCameraCaptureMode.Video; picker.VideoQuality = GetQuailty(voptions.Quality); picker.VideoMaximumDuration = voptions.DesiredLength.TotalSeconds; } } return(picker); }
private bool IsPickerTypeAvailable(UIImagePickerControllerSourceType type) { return UIImagePickerController.IsSourceTypeAvailable(type); }
private Task<List<MediaFile>> GetPickMediaAsync(UIImagePickerControllerSourceType sourceType, string mediaType, MediaStorageOptions options = null) { UIWindow window = UIApplication.SharedApplication.KeyWindow; if (window == null) throw new InvalidOperationException ("There's no current active window"); string TypeImage = "public.image"; const string TypeMovie = "public.movie"; UIViewController viewController = window.RootViewController; if (mediaType == TypeImage) { var picker = ELCImagePickerViewController.Instance (ALAssetsFilter.AllPhotos); viewController.PresentViewController (picker, true, null); return picker.Completion.ContinueWith (t => { //Interlocked.Exchange (ref this.pickerDelegate, null); viewController.DismissViewController(true,null); return t; }).Unwrap (); } else if (mediaType == TypeMovie) { var picker = ELCImagePickerViewController.Instance (ALAssetsFilter.AllVideos); viewController.PresentViewController (picker, true, null); return picker.Completion.ContinueWith (t => { Interlocked.Exchange (ref this.pickerDelegate, null); return t; }).Unwrap (); } return null; // PresentViewController (picker, true, null); // return ndelegate.Task.ContinueWith (t => { // if (this.popover != null) { // this.popover.Dispose(); // this.popover = null; // } // // Interlocked.Exchange (ref this.pickerDelegate, null); // return t; // }).Unwrap(); }
static public void ImageImport(UIImagePickerControllerSourceType sourceType, NSUrlRequest request) { var imagePicker = new UIImagePickerController { SourceType = sourceType }; imagePicker.FinishedPickingMedia += (send, ev) => { var image = (UIImage)ev.Info.ObjectForKey(new NSString("UIImagePickerControllerOriginalImage")); var filename = String.Format("Pic_{0}.png", NoSeqGenerator.Generate()); var filepath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), filename); using (NSData imageData = image.AsPNG()) { Byte[] byteArray = new Byte[imageData.Length]; System.Runtime.InteropServices.Marshal.Copy(imageData.Bytes, byteArray, 0, Convert.ToInt32(imageData.Length)); App.FileHelper.SaveImage(filepath, byteArray); } UIApplication.SharedApplication.KeyWindow.RootViewController.DismissViewController(true, null); var imageEditor = new PheidiTOCropViewController(image); imageEditor.OnEditFinished(() => { var param = request.Body.ToString().Split('&'); PheidiParams pp = new PheidiParams(); int index = 0; for (int i = 0; i < param.Length; i++) { if (param[i].Contains("pheidiparams")) { pp.Load(WebUtility.UrlDecode(param[i])); index = i; } } image = imageEditor.FinalImage; if (image != null) { using (NSData imageData = image.AsJPEG()) { Byte[] byteArray = new Byte[imageData.Length]; System.Runtime.InteropServices.Marshal.Copy(imageData.Bytes, byteArray, 0, Convert.ToInt32(imageData.Length)); App.FileHelper.SaveImage(filepath, byteArray); } if (App.NetworkManager.GetHostServerState() == NetworkState.Reachable && (App.NetworkManager.GetNetworkState() == NetworkState.ReachableViaWiFiNetwork || App.WifiOnlyEnabled == false)) { Task.Run(async() => { await UploadImageToServer(image, filename, filepath, pp); }); } else { string title = ""; string message = ""; if (App.NetworkManager.GetHostServerState() == NetworkState.NotReachable) { title = AppResources.Alerte_ImageUploadHoteInacessibleTitle; message = AppResources.Alerte_ImageUploadHoteInacessibleMessage; } else if (App.WifiOnlyEnabled) { title = AppResources.Alerte_ImageUploadPasDeWifiTitle; message = AppResources.Alerte_ImageUploadPasDeWifiMessage; } App.NotificationManager.DisplayAlert(message, title, "OK", () => { }); Task.Run(async() => { var iu = new ImageUpload() { FileName = filename, FilePath = filepath, Field = pp["FIELD"], QueryFieldValue = pp["NOSEQ"], User = App.UserNoseq, ServerNoseq = App.CurrentServer.Noseq }; await DatabaseHelper.Database.SaveItemAsync(iu); }); } } }); UIApplication.SharedApplication.KeyWindow.RootViewController.PresentViewController(imageEditor, true, () => { }); }; imagePicker.Canceled += (send, ev2) => { UIApplication.SharedApplication.KeyWindow.RootViewController.DismissViewController(true, null); }; UIApplication.SharedApplication.KeyWindow.RootViewController.PresentViewController(imagePicker, true, null); }
private Task<MediaFile> GetMediaAsync (UIImagePickerControllerSourceType sourceType, string mediaType, StoreCameraMediaOptions options = null) { UIWindow window = UIApplication.SharedApplication.KeyWindow; if (window == null) throw new InvalidOperationException ("There's no current active window"); UIViewController viewController = window.RootViewController; if (viewController == null) { window = UIApplication.SharedApplication.Windows.OrderByDescending (w => w.WindowLevel).FirstOrDefault (w => w.RootViewController != null); if (window == null) throw new InvalidOperationException ("Could not find current view controller"); else viewController = window.RootViewController; } while (viewController.PresentedViewController != null) viewController = viewController.PresentedViewController; MediaPickerDelegate ndelegate = new MediaPickerDelegate (viewController, sourceType, options); var od = Interlocked.CompareExchange (ref this.pickerDelegate, ndelegate, null); if (od != null) throw new InvalidOperationException ("Only one operation can be active at at time"); var picker = SetupController (ndelegate, sourceType, mediaType, options); if (UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad && sourceType == UIImagePickerControllerSourceType.PhotoLibrary) { ndelegate.Popover = new UIPopoverController (picker); ndelegate.Popover.Delegate = new MediaPickerPopoverDelegate (ndelegate, picker); ndelegate.DisplayPopover(); } else viewController.PresentViewController (picker, true, null); return ndelegate.Task.ContinueWith (t => { if (this.popover != null) { this.popover.Dispose(); this.popover = null; } Interlocked.Exchange (ref this.pickerDelegate, null); return t; }).Unwrap(); }
private static MediaPickerController SetupController (MediaPickerDelegate mpDelegate, UIImagePickerControllerSourceType sourceType, string mediaType, StoreCameraMediaOptions options = null) { var picker = new MediaPickerController (mpDelegate); picker.MediaTypes = new[] { mediaType }; picker.SourceType = sourceType; if (sourceType == UIImagePickerControllerSourceType.Camera) { picker.CameraDevice = GetUICameraDevice (options.DefaultCamera); if (mediaType == TypeImage) picker.CameraCaptureMode = UIImagePickerControllerCameraCaptureMode.Photo; else if (mediaType == TypeMovie) { StoreVideoOptions voptions = (StoreVideoOptions)options; picker.CameraCaptureMode = UIImagePickerControllerCameraCaptureMode.Video; picker.VideoQuality = GetQuailty (voptions.Quality); picker.VideoMaximumDuration = voptions.DesiredLength.TotalSeconds; } } return picker; }
/// <summary> /// Setups the controller. /// </summary> /// <param name="mpDelegate">The mp delegate.</param> /// <param name="sourceType">Type of the source.</param> /// <param name="mediaType">Type of the media.</param> /// <param name="options">The options.</param> /// <returns>MediaPickerController.</returns> private static MediaPickerController SetupController( MediaPickerDelegate mpDelegate, UIImagePickerControllerSourceType sourceType, string mediaType, MediaStorageOptions options = null) { var picker = new MediaPickerController(mpDelegate) { MediaTypes = new[] { mediaType }, SourceType = sourceType}; if (sourceType == UIImagePickerControllerSourceType.Camera) { if (mediaType == TypeImage && options is CameraMediaStorageOptions) { picker.CameraDevice = GetCameraDevice(((CameraMediaStorageOptions)options).DefaultCamera); picker.CameraCaptureMode = UIImagePickerControllerCameraCaptureMode.Photo; } else if (mediaType == TypeMovie && options is VideoMediaStorageOptions) { var voptions = (VideoMediaStorageOptions)options; picker.CameraDevice = GetCameraDevice (voptions.DefaultCamera); picker.CameraCaptureMode = UIImagePickerControllerCameraCaptureMode.Video; picker.VideoQuality = GetQuailty(voptions.Quality); picker.VideoMaximumDuration = voptions.DesiredLength.TotalSeconds; } } return picker; }
public static bool IsSourceTypeAvailable(UIImagePickerControllerSourceType sourceType) { return(default(bool)); }
public static AnyObject[] AvailableMediaTypesForSourceType(UIImagePickerControllerSourceType sourceType) { return(default(AnyObject[])); }
/// <summary> /// Shows the image picker. /// </summary> public static void ShowImagePicker(UIImagePickerControllerSourceType source = UIImagePickerControllerSourceType.PhotoLibrary, UIImagePickerControllerCameraDevice cameraDevice = UIImagePickerControllerCameraDevice.Rear) { _picker = new UIImagePickerController(); // _picker.AllowsEditing = true; _picker.sourceType = source; // _picker.Delegate = ImagePickerControllerDelegate.instance; _picker.DidFinishPickingMediaWithInfo += _OnPickedMedia; _picker.DidCancel += _OnCancelledPick; if (source == UIImagePickerControllerSourceType.Camera) _picker.cameraDevice = cameraDevice; var rootVc = UIApplication.deviceRootViewController; if (CoreXT.IsiPad && (source != UIImagePickerControllerSourceType.Camera)) { if (_popover == null) { _popover = new UIPopoverController(_picker); _popover.DidDismiss += _OnCancelledPick; _popover.shouldDismissHandler = _ShouldDismissPopover; } else { _popover.contentViewController = _picker; } var rect = rootVc.view.bounds; rect.x = rect.width / 2; rect.y = rect.height; rect.width = 1; rect.height = 1; _popover.PresentPopover( rect, rootVc.view, UIPopoverArrowDirection.Down, true); } else { rootVc.PresentViewController(_picker, true, null); } }
private Task <MediaFile> GetMediaAsync(UIImagePickerControllerSourceType sourceType, string mediaType, StoreCameraMediaOptions options = null, CancellationToken token = default(CancellationToken)) { UIViewController viewController = null; UIWindow window = UIApplication.SharedApplication.KeyWindow; if (window == null) { throw new InvalidOperationException("There's no current active window"); } if (window.WindowLevel == UIWindowLevel.Normal) { viewController = window.RootViewController; } if (viewController == null) { window = UIApplication.SharedApplication.Windows.OrderByDescending(w => w.WindowLevel).FirstOrDefault(w => w.RootViewController != null && w.WindowLevel == UIWindowLevel.Normal); if (window == null) { throw new InvalidOperationException("Could not find current view controller"); } else { viewController = window.RootViewController; } } while (viewController.PresentedViewController != null) { viewController = viewController.PresentedViewController; } if (token.IsCancellationRequested) { return(Task.FromResult((MediaFile)null)); } MediaPickerDelegate ndelegate = new MediaPickerDelegate(viewController, sourceType, options, token); var od = Interlocked.CompareExchange(ref pickerDelegate, ndelegate, null); if (od != null) { throw new InvalidOperationException("Only one operation can be active at a time"); } var picker = SetupController(ndelegate, sourceType, mediaType, options); if (UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad && sourceType == UIImagePickerControllerSourceType.PhotoLibrary) { ndelegate.Popover = popover = new UIPopoverController(picker); ndelegate.Popover.Delegate = new MediaPickerPopoverDelegate(ndelegate, picker); ndelegate.DisplayPopover(); token.Register(() => { if (popover == null) { return; } NSRunLoop.Main.BeginInvokeOnMainThread(() => { ndelegate.Popover.Dismiss(true); ndelegate.CancelTask(); }); }); } else { if (UIDevice.CurrentDevice.CheckSystemVersion(9, 0)) { picker.ModalPresentationStyle = options?.ModalPresentationStyle == MediaPickerModalPresentationStyle.OverFullScreen ? UIModalPresentationStyle.OverFullScreen : UIModalPresentationStyle.FullScreen; } viewController.PresentViewController(picker, true, null); token.Register(() => { if (picker == null) { return; } NSRunLoop.Main.BeginInvokeOnMainThread(() => { picker.DismissModalViewController(true); ndelegate.CancelTask(); }); }); } return(ndelegate.Task.ContinueWith(t => { try { popover?.Dispose(); } catch { } popover = null; Interlocked.Exchange(ref pickerDelegate, null); try { picker?.Dispose(); } catch { } picker = null; return t; }).Unwrap()); }
private Task <MediaFile> GetMediaAsync(UIImagePickerControllerSourceType sourceType, string mediaType, StoreCameraMediaOptions options = null) { UIWindow window = UIApplication.SharedApplication.KeyWindow; if (window == null) { throw new InvalidOperationException("There's no current active window"); } UIViewController viewController = window.RootViewController; if (viewController == null) { window = UIApplication.SharedApplication.Windows.OrderByDescending(w => w.WindowLevel).FirstOrDefault(w => w.RootViewController != null); if (window == null) { throw new InvalidOperationException("Could not find current view controller"); } else { viewController = window.RootViewController; } } while (viewController.PresentedViewController != null) { viewController = viewController.PresentedViewController; } MediaPickerDelegate ndelegate = new MediaPickerDelegate(viewController, sourceType, options); var od = Interlocked.CompareExchange(ref this.pickerDelegate, ndelegate, null); if (od != null) { throw new InvalidOperationException("Only one operation can be active at at time"); } var picker = SetupController(ndelegate, sourceType, mediaType, options); if (UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad && sourceType == UIImagePickerControllerSourceType.PhotoLibrary) { ndelegate.Popover = new UIPopoverController(picker); ndelegate.Popover.Delegate = new MediaPickerPopoverDelegate(ndelegate, picker); ndelegate.DisplayPopover(); } else { viewController.PresentViewController(picker, true, null); } return(ndelegate.Task.ContinueWith(t => { if (this.popover != null) { this.popover.Dispose(); this.popover = null; } Interlocked.Exchange(ref this.pickerDelegate, null); return t; }).Unwrap()); }
private void ShowImagePicker(UIViewController viewController, UIImagePickerControllerSourceType pickerType) { imagePicker = new UIImagePickerController(); imagePicker.SourceType = pickerType; // only allow photos (not videos) imagePicker.MediaTypes = new string[] { UTType.Image }; if (pickerType == UIImagePickerControllerSourceType.Camera) { imagePicker.ShowsCameraControls = true; } imagePicker.FinishedPickingMedia += (s, e) => { viewController.InvokeOnMainThread(() => { bool didPickAnImage = e.MediaType == ImageMediaType && e.OriginalImage != null; OnFinishedPicking(didPickAnImage, e.OriginalImage); }); }; imagePicker.Canceled += (object s, EventArgs e) => { OnFinishedPicking(false, null); }; imagePicker.ModalInPopover = true; imagePicker.ModalPresentationStyle = UIModalPresentationStyle.FullScreen; imagePicker.ModalTransitionStyle = UIModalTransitionStyle.CoverVertical; viewController.PresentViewController(imagePicker, true, null); }
/// <summary> /// Shows the image picker. /// </summary> public static void ShowImagePicker(UIImagePickerControllerSourceType source = UIImagePickerControllerSourceType.PhotoLibrary) { _picker = new UIImagePickerController(); // _picker.AllowsEditing = true; _picker.sourceType = source; // _picker.Delegate = ImagePickerControllerDelegate.instance; _picker.DidFinishPickingMediaWithInfo += _OnPickedMedia; _picker.DidCancel += _OnCancelledPick; var rootVc = UIApplication.SharedApplication().keyWindow.rootViewController; if (CoreXT.IsiPad && (source != UIImagePickerControllerSourceType.Camera)) { if (_popover == null) _popover = new UIPopoverController(_picker); else _popover.contentViewController = _picker; var rect = rootVc.view.bounds; rect.x = rect.width / 2; rect.y = rect.height; rect.width = 1; rect.height = 1; _popover.PresentPopover( rect, rootVc.view, UIPopoverArrowDirection.Down, true); } else { rootVc.PresentViewController(_picker, true, null); } }