private void SelectImage() { var imagePicker = new RotatableUIImagePickerController(); imagePicker.NavigationControllerDelegate = new ImagePickerDelegate(); imagePicker.SourceType = UIImagePickerControllerSourceType.PhotoLibrary; imagePicker.MediaTypes = UIImagePickerController.AvailableMediaTypes(UIImagePickerControllerSourceType.PhotoLibrary); imagePicker.MediaTypes = imagePicker.MediaTypes.Where(x => !(x.Contains("movie") || x.Contains("video"))).ToArray(); imagePicker.FinishedPickingMedia += (sender, e) => { // determine what was selected, video or image bool isImage = false; switch (e.Info[UIImagePickerController.MediaType].ToString()) { case "public.image": isImage = true; break; } // if it was an image, get the other image info if (isImage) { // get the original image UIImage originalImage = e.Info[UIImagePickerController.OriginalImage] as UIImage; if (originalImage != null) { // do something with the image try { UploadImage(originalImage); } catch { } } } else { // if it's a video AlertDialogService.ShowAlert("Not supported!", "Video upload is currently not supported."); } // dismiss the picker imagePicker.DismissViewController(true, null); UIApplication.SharedApplication.StatusBarStyle = UIStatusBarStyle.LightContent; }; imagePicker.Canceled += (sender, e) => { imagePicker.DismissViewController(true, null); UIApplication.SharedApplication.StatusBarStyle = UIStatusBarStyle.LightContent; }; NavigationController.PresentViewController(imagePicker, true, null); }
private void SelectImage() { var imagePicker = new RotatableUIImagePickerController(); imagePicker.NavigationControllerDelegate = new ImagePickerDelegate(); imagePicker.SourceType = UIImagePickerControllerSourceType.PhotoLibrary; imagePicker.MediaTypes = UIImagePickerController.AvailableMediaTypes(UIImagePickerControllerSourceType.PhotoLibrary); imagePicker.MediaTypes = imagePicker.MediaTypes.Where(x => !(x.Contains("movie") || x.Contains("video"))).ToArray(); imagePicker.FinishedPickingMedia += (sender, e) => { // determine what was selected, video or image bool isImage = false; switch(e.Info[UIImagePickerController.MediaType].ToString()) { case "public.image": isImage = true; break; } // if it was an image, get the other image info if(isImage) { // get the original image UIImage originalImage = e.Info[UIImagePickerController.OriginalImage] as UIImage; if(originalImage != null) { // do something with the image try { UploadImage(originalImage); } catch { } } } else { // if it's a video MonoTouch.Utilities.ShowAlert("Not supported!", "Video upload is currently not supported."); } // dismiss the picker imagePicker.DismissViewController(true, null); UIApplication.SharedApplication.StatusBarStyle = UIStatusBarStyle.LightContent; }; imagePicker.Canceled += (sender, e) => { imagePicker.DismissViewController(true, null); UIApplication.SharedApplication.StatusBarStyle = UIStatusBarStyle.LightContent; }; NavigationController.PresentViewController(imagePicker, true, null); }