public override void FinishedPickingMedia (UIImagePickerController picker, NSDictionary info) { var cb = _callback; _callback = null; picker.DismissViewController (true,null); cb (info); }
public MvxImagePickerTask(IMvxTouchViewPresenter presenter) { _picker = new UIImagePickerController(); //_cameraDelegate = new CameraDelegate(); // _picker.Delegate = _cameraDelegate; _presenter = presenter; }
public async Task<IMediaFile> PickPhotoAsync() { Debug.WriteLine("PickPhotoAsync: starting"); // setup a task to get the results back from the delegate var mediaInfoTask = new TaskCompletionSource<NSDictionary>(); // setup a UI Picker to show photos var picker = new UIImagePickerController(); picker.SourceType = UIImagePickerControllerSourceType.PhotoLibrary; picker.MediaTypes = new string[] { UTType.Image }; picker.AllowsEditing = false; picker.Delegate = new MediaDelegate { InfoTask = mediaInfoTask }; // iPad should display the picker in a popover if (UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad) picker.ModalInPopover = true; var vc = GetViewController(); Debug.WriteLine("PickPhotoAsync: displaying photo picker"); vc.PresentViewController(picker, true, null); // wait to get the results back Debug.WriteLine("PickPhotoAsync: waiting for selected photo"); var info = await mediaInfoTask.Task; var assetUrl = info[UIImagePickerController.ReferenceUrl] as NSUrl; Debug.WriteLine("PickPhotoAsync: photo selected {0}", assetUrl); var mediaFile = new MediaFile {Path = assetUrl.ToString()}; Debug.WriteLine("PickPhotoAsync: returning created media file"); return mediaFile; }
void AddNewItem (object sender, EventArgs args) { var picker = new UIImagePickerController (); this.NavigationController.PresentViewController (picker, true, new NSAction(()=>{ Console.WriteLine("done."); })); picker.FinishedPickingMedia += (object s, UIImagePickerMediaPickedEventArgs e) => { Title = NSBundle.MainBundle.LocalizedString ("Uploading photo...", "Uploading photo..."); picker.DismissViewController (true, null); var randomInt = Convert.ToUInt64(new Random().NextDouble() * UInt64.MaxValue); var name = randomInt + ".png"; UploadTask = new TaskFactory<CloudBlockBlob>().StartNew(()=>{ return UploadImage(e.OriginalImage, name); }) .ContinueWith((blob)=>{ InvokeOnMainThread(()=>{ dataSource.Objects.Insert (0, new Tuple<String, UIImage>(name, e.OriginalImage)); Title = NSBundle.MainBundle.LocalizedString ("Photos", "Photos"); using (var indexPath = NSIndexPath.FromRowSection (0, 0)) TableView.InsertRows (new NSIndexPath[] { indexPath }, UITableViewRowAnimation.Automatic); }); }); }; picker.Canceled += (s, e) => { picker.DismissViewController (true, null); }; }
public override void ViewDidLoad() { base.ViewDidLoad (); this.CreateAccount.TouchUpInside += (object sender, EventArgs e) => { //UIStoryboard board = UIStoryboard.FromName ("MainStoryboard", null); //PreferencesController welcome = (PreferencesController)board.InstantiateViewController ("preferencescontroller"); //welcome.ImageSources = new string[] { "aaa", "a", "a", "a", "a", "a", "a", "a", "a" }; //this.NavigationController.PushViewController(welcome, true); model = new RegisterModel { Email = this.Email.Text, FirstName = this.FirstName.Text, LastName = this.LastName.Text, Password = this.Password.Text }; var request = new RestRequest(); request.Send("http://www.sport.net/api/content/register", "POST", model); }; this.ImagePicker.TouchUpInside += (s, e) => { // create a new picker controller imagePicker = new UIImagePickerController (); // set our source to the photo library imagePicker.SourceType = UIImagePickerControllerSourceType.PhotoLibrary; // set what media types imagePicker.MediaTypes = UIImagePickerController.AvailableMediaTypes (UIImagePickerControllerSourceType.PhotoLibrary); imagePicker.FinishedPickingMedia += Handle_FinishedPickingMedia; imagePicker.Canceled += Handle_Canceled; // show the picker NavigationController.PresentViewController (imagePicker, true, null); }; }
public bool GetImagePath() { string ImageRefURL = null; imagePicker = new UIImagePickerController (); imagePicker.SourceType = UIImagePickerControllerSourceType.PhotoLibrary; imagePicker.MediaTypes = UIImagePickerController.AvailableMediaTypes (UIImagePickerControllerSourceType.PhotoLibrary); imagePicker.FinishedPickingMedia += (object sender, UIImagePickerMediaPickedEventArgs e) => { // determine what was selected, video or image bool isImage = false; switch (e.Info [UIImagePickerController.MediaType].ToString ()) { case "public.image": // Console.WriteLine("Image selected"); isImage = true; break; case "public.video": // Console.WriteLine("Video selected"); break; } // get common info (shared between images and video) NSUrl referenceURL = e.Info [new NSString ("UIImagePickerControllerReferenceUrl")] as NSUrl; if (referenceURL != null && isImage) { ImageRefURL = referenceURL.ToString(); } }; return true; }
public async Task<IMediaFile> TakePhotoAsync() { Debug.WriteLine("TakePhotoAsync: starting"); // setup a task to get the results back from the delegate var mediaInfoTask = new TaskCompletionSource<NSDictionary>(); // setup a UI Picker to display camera var picker = new UIImagePickerController(); picker.SourceType = UIImagePickerControllerSourceType.Camera; picker.MediaTypes = new string[] { UTType.Image }; picker.AllowsEditing = false; picker.Delegate = new MediaDelegate { InfoTask = mediaInfoTask }; // display the picker Debug.WriteLine("TakePhotoAsync: displaying the camera"); var vc = GetViewController(); vc.PresentViewController(picker, true, null); // wait for a result Debug.WriteLine("TakePhotoAsync: waiting for photo from camera"); var info = await mediaInfoTask.Task; var assetLocation = await SavePhotoWithLocationAsync(info); // create and return a media file Debug.WriteLine("TakePhotoAsync: picture taken & stored at {0}", assetLocation); var mediaFile = new MediaFile {Path = assetLocation.ToString()}; Debug.WriteLine("TakePhotoAsync: returning created media file"); return mediaFile; }
public override void ViewDidLoad () { this.Root.Add(new Section() { new StyledStringElement("Load App's Sample Photo", () => { Decode(UIImage.FromFile("BarcodeSamples/" + this.Format.ToString().ToLower() + ".png")); }), new StyledStringElement("Choose Existing Photo", () => { var ipc = new UIImagePickerController(); ipc.FinishedPickingImage += (sender, e) => { Decode(e.Image); this.InvokeOnMainThread(() => this.NavigationController.DismissViewController(true, null)); }; ipc.FinishedPickingMedia += (sender, e) => { Decode(e.EditedImage ?? e.OriginalImage); this.InvokeOnMainThread(() => this.NavigationController.DismissViewController(true, null)); }; ipc.Canceled += (sender, e) => { this.InvokeOnMainThread(() => this.NavigationController.DismissViewController(true, null)); }; this.InvokeOnMainThread(() => this.NavigationController.PresentViewController(ipc, true, null)); }), new StyledStringElement("Take new Photo", () => { }) }); this.Root.Add (new Section() { new ImageDisplayElement(null, 160f), new StyledStringElement("Decoded Results will appear here") }); }
public override void ViewDidLoad() { base.ViewDidLoad(); Title = "Choose Photo"; View.BackgroundColor = UIColor.White; imageView = new UIImageView(new CGRect(10, 150, 300, 300)); Add(imageView); choosePhotoButton = UIButton.FromType(UIButtonType.RoundedRect); choosePhotoButton.Frame = new CGRect(10, 80, 100, 40); choosePhotoButton.SetTitle("Picker", UIControlState.Normal); choosePhotoButton.TouchUpInside += (s, e) => { // create a new picker controller imagePicker = new UIImagePickerController(); // set our source to the photo library imagePicker.SourceType = UIImagePickerControllerSourceType.PhotoLibrary; // set what media types imagePicker.MediaTypes = UIImagePickerController.AvailableMediaTypes(UIImagePickerControllerSourceType.PhotoLibrary); imagePicker.FinishedPickingMedia += Handle_FinishedPickingMedia; imagePicker.Canceled += Handle_Canceled; // show the picker NavigationController.PresentModalViewController(imagePicker, true); //UIPopoverController picc = new UIPopoverController(imagePicker); }; View.Add(choosePhotoButton); }
public override void FinishedPickingImage (UIImagePickerController picker, UIImage image, NSDictionary editingInfo) { UIApplication.SharedApplication.SetStatusBarHidden(false, false); var imagePicker = (VCViewController)_navigationController; if (imagePicker.IsCameraAvailable) imagePicker.btnBib.Hidden = true; imagePicker.DismissModalViewControllerAnimated(true); if (imagePicker.IsCameraAvailable) { image.SaveToPhotosAlbum (delegate { // ignore errors }); } UIViewController nextScreen = null; if (tweet != null) { nextScreen = new PhotoPostViewController(_shareNavCont, image, tweet); } else { nextScreen = new PhotoLocationViewController(_shareNavCont, image); } _shareNavCont.PushViewController(nextScreen, true); }
void OnTakePhotoPressed (object sender, EventArgs eventArgs) { TakePhotoButton.Enabled = false; UIImagePickerController picker = new UIImagePickerController (); picker.SourceType = UIImagePickerControllerSourceType.Camera; picker.FinishedPickingMedia += async (o, e) => { // Create a moderate quality version of the image byte [] dataBytes; using (NSData data = e.OriginalImage.AsJPEG (.5f)) { dataBytes = new byte [data.Length]; System.Runtime.InteropServices.Marshal.Copy (data.Bytes, dataBytes, 0, Convert.ToInt32 (data.Length)); } ThePhoto.Image = e.OriginalImage; DetailsText.Text = "Processing..."; ((UIImagePickerController)o).DismissViewController (true, null); // Create a stream, send it to MCS, and get back using (MemoryStream stream = new MemoryStream (dataBytes)) { try { float happyValue = await SharedProject.Core.GetAverageHappinessScore (stream); DetailsText.Text = SharedProject.Core.GetHappinessMessage (happyValue); } catch (Exception ex) { DetailsText.Text = ex.Message; } TakePhotoButton.Enabled = true; } }; PresentModalViewController (picker, true); }
public override void FinishedPickingMedia(UIImagePickerController picker, NSDictionary info) { MediaFile mediaFile; switch ((NSString)info[UIImagePickerController.MediaType]) { case MediaImplementation.TypeImage: mediaFile = GetPictureMediaFile(info); break; case MediaImplementation.TypeMovie: mediaFile = GetMovieMediaFile(info); break; default: throw new NotSupportedException(); } if (UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Phone) { UIApplication.SharedApplication.SetStatusBarStyle(MediaImplementation.StatusBarStyle, false); } Dismiss(picker, () => { this.tcs.TrySetResult(mediaFile); }); }
public override void ViewDidLoad () { base.ViewDidLoad (); _picker = new UIImagePickerController (); _pickerDel = new PickerDelegate (this); _picker.Delegate = _pickerDel; _actionSheet = new UIActionSheet (); _actionSheet.AddButton ("Library"); _actionSheet.AddButton ("Camera"); _actionSheet.AddButton ("Cancel"); _actionSheet.CancelButtonIndex = 2; _actionSheet.Delegate = new ActionSheetDelegate (this); showPicker.TouchUpInside += delegate { _actionSheet.ShowInView (this.View); }; playMovie.Hidden = true; playMovie.TouchUpInside += delegate { if (_mp != null) { View.AddSubview (_mp.View); _mp.SetFullscreen (true, true); _mp.Play (); } }; }
public override void ViewDidLoad() { uploadVideo.Enabled = false; pickerController = new UIImagePickerController(); pickerController.SourceType = UIImagePickerControllerSourceType.PhotoLibrary; pickerController.MediaTypes = UIImagePickerController.AvailableMediaTypes (UIImagePickerControllerSourceType.PhotoLibrary); pickerController.FinishedPickingMedia += finishPickImage; pickerController.Canceled += cancelImagePicker; selectVideo.TouchUpInside += (sender, e) => PresentViewController (pickerController, true, null); uploadVideo.TouchUpInside += (sender, e) => { uploadResult = new CISolution.CloudinaryHelper().uploadVideo(fd); if(uploadResult.Error == null) { alertController = UIAlertController.Create("Success", uploadResult.JsonObj.ToString(), UIAlertControllerStyle.ActionSheet); } else { alertController = UIAlertController.Create("Error", uploadResult.Error.Message, UIAlertControllerStyle.ActionSheet); } alertController.AddAction(UIAlertAction.Create("Cancel", UIAlertActionStyle.Cancel, null)); PresentViewController(alertController,true,null); uploadVideo.Enabled = false; }; }
public override void FinishedPickingMedia(UIImagePickerController picker, NSDictionary info) { //Determine that an image was selected bool isImage = false; switch (info [UIImagePickerController.MediaType].ToString ()) { case "public.image": isImage = true; break; } //If it was an image, get the image if (isImage) { //Get the image - either it will be original, or edited var originalImage = info [UIImagePickerController.OriginalImage] as UIImage; var editedImage = info [UIImagePickerController.EditedImage] as UIImage; UIImage image = null; if (originalImage != null) image = originalImage; else if (editedImage != null) image = editedImage; picker.DismissViewController (false, () => _parentViewController.ExtractResults (image, true)); return; } picker.DismissViewController (false, () => new UIAlertView ("Image not processed", "Image could not be processed", null, "OK").Show ()); }
public override void ViewDidLoad() { uploadImage.Enabled = false; imagePicker = new UIImagePickerController(); imagePicker.SourceType = UIImagePickerControllerSourceType.PhotoLibrary; imagePicker.MediaTypes = UIImagePickerController.AvailableMediaTypes (UIImagePickerControllerSourceType.PhotoLibrary); imagePicker.FinishedPickingMedia += finishPickImage; imagePicker.Canceled += cancelImagePicker; selectImage.TouchUpInside += (sender, e) => { Console.WriteLine ("Execute image picker controller"); PresentViewController(imagePicker,true, null); }; uploadImage.TouchUpInside += (sender, e) => { uploadResult = new CISolution.CloudinaryHelper().uploadImage(fd); if(uploadResult.Error == null) { Console.WriteLine("Video success uploaded..."); } else { Console.WriteLine("Error : " + uploadResult.Error.Message); } uploadImage.Enabled = false; }; }
public void OpenCameraViewController(object sender, EventArgs ea) { picker = new UIImagePickerController(); picker.AllowsEditing = true; if(UIImagePickerController.IsSourceTypeAvailable(UIImagePickerControllerSourceType.Camera)) { picker.SourceType = UIImagePickerControllerSourceType.Camera; } else if(UIImagePickerController.IsSourceTypeAvailable(UIImagePickerControllerSourceType.PhotoLibrary)) { picker.SourceType = UIImagePickerControllerSourceType.PhotoLibrary; } picker.FinishedPickingMedia += (s, e) => { UIImage editedImage = e.Info[UIImagePickerController.EditedImage] as UIImage; imageViewPhoto.Image = editedImage; picker.DismissViewController (true, null); }; picker.Canceled += (s, e) => { picker.DismissViewController(true, null); }; PresentViewController(picker, true, null); }
public override void Canceled(UIImagePickerController picker) { var cb = _callback; _callback = null; picker.DismissViewController(true, (Action)null); cb(null); }
public ImagePickerProvider(UIViewController viewController) { _viewController = viewController; _imagePicker = new UIImagePickerController (); _imagePicker.SourceType = UIImagePickerControllerSourceType.PhotoLibrary; _imagePicker.MediaTypes = UIImagePickerController.AvailableMediaTypes (UIImagePickerControllerSourceType.PhotoLibrary); }
static void Init () { if (picker != null) return; picker = new UIImagePickerController (); picker.Delegate = new CameraDelegate (); }
public override void FinishedPickingMedia(UIImagePickerController picker, MonoTouch.Foundation.NSDictionary info) { var originalImage = new NSString("UIImagePickerControllerOriginalImage"); var image = (UIImage)info[originalImage]; _controller.LoadImage(image); _controller.DismissModalViewControllerAnimated(true); }
private void cameraButtonClicked(Object obj, EventArgs e) { Console.WriteLine ("Camera button clicked"); UIImagePickerController imagePicker = new UIImagePickerController (); imagePicker.SourceType = UIImagePickerControllerSourceType.PhotoLibrary; imagePicker.FinishedPickingMedia += handle_FinishedPickingMedia; imagePicker.Canceled += handle_Cancled; NavigationController.PresentModalViewController (imagePicker, true); }
public override void FinishedPickingImage (UIImagePickerController picker, UIImage image, NSDictionary editingInfo) { var cb = _callbackImg; _oncancel = null; _callbackImg = null; picker.DismissModalViewControllerAnimated(true); cb(image); }
public override void Canceled (UIImagePickerController picker) { var cb = _oncancel; _oncancel = null; _callbackImg = null; picker.DismissModalViewControllerAnimated(true); cb(); }
private void ChooseImageFromLibrary() { this.imagePicker = new UIImagePickerController(); this.imagePicker.SourceType = UIImagePickerControllerSourceType.PhotoLibrary; this.imagePicker.MediaTypes = UIImagePickerController.AvailableMediaTypes(UIImagePickerControllerSourceType.PhotoLibrary); this.imagePicker.FinishedPickingMedia += Handle_FinishedPickingMedia; this.imagePicker.Canceled += Handle_Canceled; this.NavigationController.PresentViewController(imagePicker, true, null); }
public async Task<IBitmap> PickPhoto() { var tcs = new TaskCompletionSource<IBitmap>(); var imagePicker = new UIImagePickerController(); 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) => { try { // 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) throw new InvalidOperationException("Video upload is currently not supported."); // get the original image var originalImage = e.Info[UIImagePickerController.OriginalImage] as UIImage; if(originalImage == null) throw new InvalidOperationException("Unable to retrieve image from picker!"); // dismiss the picker imagePicker.DismissViewController(true, null); UIApplication.SharedApplication.StatusBarStyle = UIStatusBarStyle.LightContent; tcs.SetResult(originalImage.FromNative()); } catch (Exception ex) { tcs.SetException(ex); } }; imagePicker.Canceled += (sender, e) => tcs.SetCanceled(); UIApplication.SharedApplication.KeyWindow.GetVisibleViewController().PresentViewController(imagePicker, true, null); try { return await tcs.Task; } finally { imagePicker.DismissViewController(true, null); UIApplication.SharedApplication.StatusBarStyle = UIStatusBarStyle.LightContent; } }
public CameraOverlay(Action<NSDictionary> callback) : base("CameraOverlay", null) { // Initialise the camera... this.camera = new UIImagePickerController(); this.camera.SourceType = UIImagePickerControllerSourceType.Camera; this.camera.CameraOverlayView = this.View; this.camera.Delegate = new CameraDelegate(callback); this.camera.ShowsCameraControls = false; }
public MediaService(BaseViewController controller) { _controller = controller; // create a new picker controller _imagePicker = new UIImagePickerController(); _imagePicker.FinishedPickingMedia += Handle_FinishedPickingMedia; _imagePicker.Canceled += Handle_Canceled; }
public override void FinishedPickingMedia (UIImagePickerController picker, NSDictionary info) { var results = info[ZBarSDK.BarcodeResultsKey]; var symbolSet = results as ZBarSymbolSet; if ( symbolSet != null ) parentController.ZBarSymbolsDetected(symbolSet, picker); else Console.WriteLine("ZBar result not a ZBarSymbolSet ({0}).",results.GetType()); }
public override void FinishedPickingMedia(UIImagePickerController picker, NSDictionary info) { UIImage image = (UIImage)info.ObjectForKey(new NSString("UIImagePickerControllerOriginalImage")); // do whatever else you'd like to with the image Console.WriteLine("media {0} x {1}", image.CGImage.Width, image.CGImage.Height); picker.DismissModalViewControllerAnimated(true); _imageView.Image = image; if (_popover != null && _popover.PopoverVisible) _popover.Dismiss(true); }
public override async void FinishedPickingMedia(UIImagePickerController picker, NSDictionary info) { if (isFinished) { return; } isFinished = true; RemoveOrientationChangeObserverAndNotifications(); MediaFile mediaFile; switch ((NSString)info[UIImagePickerController.MediaType]) { case MediaImplementation.TypeImage: mediaFile = await GetPictureMediaFile(info); break; case MediaImplementation.TypeMovie: mediaFile = await GetMovieMediaFile(info); break; default: throw new NotSupportedException(); } if (UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Phone) { UIApplication.SharedApplication.SetStatusBarStyle(MediaImplementation.StatusBarStyle, false); } Dismiss(picker, () => { if (mediaFile == null) { tcs.SetException(new FileNotFoundException()); } else { tcs.TrySetResult(new List <MediaFile> { mediaFile }); } isFinished = false; }); }
public Task SelectFileAsync() { var controller = GetVisibleViewController(); var picker = new UIDocumentMenuViewController(new string[] { UTType.Data }, UIDocumentPickerMode.Import); picker.AddOption(AppResources.Camera, UIImage.FromBundle("camera"), UIDocumentMenuOrder.First, () => { var imagePicker = new UIImagePickerController { SourceType = UIImagePickerControllerSourceType.Camera }; imagePicker.FinishedPickingMedia += ImagePicker_FinishedPickingMedia; imagePicker.Canceled += ImagePicker_Canceled; controller.PresentModalViewController(imagePicker, true); }); picker.AddOption(AppResources.Photos, UIImage.FromBundle("photo"), UIDocumentMenuOrder.First, () => { var imagePicker = new UIImagePickerController { SourceType = UIImagePickerControllerSourceType.PhotoLibrary }; imagePicker.FinishedPickingMedia += ImagePicker_FinishedPickingMedia; imagePicker.Canceled += ImagePicker_Canceled; controller.PresentModalViewController(imagePicker, true); }); picker.DidPickDocumentPicker += (sender, e) => { if (SystemMajorVersion() < 11) { e.DocumentPicker.DidPickDocument += DocumentPicker_DidPickDocument; } else { e.DocumentPicker.Delegate = new PickerDelegate(this); } controller.PresentViewController(e.DocumentPicker, true, null); }; var root = UIApplication.SharedApplication.KeyWindow.RootViewController; if (picker.PopoverPresentationController != null && root != null) { picker.PopoverPresentationController.SourceView = root.View; picker.PopoverPresentationController.SourceRect = root.View.Bounds; } controller.PresentViewController(picker, true, null); return(Task.FromResult(0)); }
public DeviceInfo() { this.Manufacturer = "Apple"; this.Model = UIDevice.CurrentDevice.Model; this.OperatingSystem = String.Format("{0} {1}", UIDevice.CurrentDevice.SystemName, UIDevice.CurrentDevice.SystemVersion); this.DeviceId = UIDevice.CurrentDevice.IdentifierForVendor.AsString(); var screen = UIScreen.MainScreen.Bounds; this.ScreenWidth = (int)screen.Width; this.ScreenHeight = (int)screen.Height; this.IsFrontCameraAvailable = UIImagePickerController.IsCameraDeviceAvailable(UIImagePickerControllerCameraDevice.Front); this.IsRearCameraAvailable = UIImagePickerController.IsCameraDeviceAvailable(UIImagePickerControllerCameraDevice.Rear); this.IsSimulator = (Runtime.Arch == Arch.SIMULATOR); //this.BatteryPercentage = UIDevice.CurrentDevice.BatteryLevel; }
private void OpenImagePickerController() { var ImagePicker = new UIImagePickerController(); ImagePicker.SourceType = UIImagePickerControllerSourceType.PhotoLibrary; ImagePicker.FinishedPickingMedia += (mSender, e) => { switch (e.Info[UIImagePickerController.MediaType].ToString()) { case "public.video": DismissViewController(true, null); return; } var SelectedImage = (UIImage)e.Info[UIImagePickerController.OriginalImage]; var DocUrl = Environment.GetFolderPath(Environment.SpecialFolder.Personal); var FileName = $"{DateTime.Now.GetHashCode().ToString()}.jpg"; var FilePath = System.IO.Path.Combine(DocUrl, FileName); nfloat Quality = 1.0f; var ImgData = SelectedImage.AsJPEG(Quality); while (ImgData.Length / 1024 > 250 && Quality > 0.1) { Quality -= 0.1f; ImgData = SelectedImage.AsJPEG(Quality); } NSError Err = null; if (ImgData.Save(FilePath, false, out Err)) { DismissViewController(true, null); chatMessageTableViewSource.CreateImageData(FileName, this); } else { SharedService.ShowErrorDialog("儲存圖片失敗", this); } }; ImagePicker.Canceled += (mSender, e) => { DismissViewController(true, null); }; PresentViewController(ImagePicker, true, null); }
private void TryOpenPhotoLibrary(UIAlertAction obj) { //Verificar que esté disponible el recurso. if (!UIImagePickerController.IsSourceTypeAvailable(UIImagePickerControllerSourceType.PhotoLibrary)) { //Imprimir un mensaje. InvokeOnMainThread(() => { ShowMessage(title: "Photo Library not available.", message: "The resource is not available due hardware configuration.", fromViewController: NavigationController); }); } else { //Revisar el estado de los permisos, para solicitarlo en dado caso que se requiera. CheckPhotoLibraryAuthorizationStatus(PHPhotoLibrary.AuthorizationStatus); } }
void CaptureImageFromCamera() { if (UIImagePickerController.IsSourceTypeAvailable(UIImagePickerControllerSourceType.Camera)) { var cameraController = new UIImagePickerController(); cameraController.SourceType = UIImagePickerControllerSourceType.Camera; cameraController.AllowsEditing = false; cameraController.Canceled += CancelPickingMedia; cameraController.FinishedPickingMedia += FinishedPickingImageFromMedia; isNavigatedForward = true; NavigationController.PresentModalViewController(cameraController, true); } else { new UIAlertView("Alert", "can't access device camera.", null, "Ok", null).Show(); } }
public void createButtons() { stackView = new UIStackView(new CGRect(0, 0, View.Bounds.Width - 40, View.Bounds.Width / 4)); stackView.Axis = UILayoutConstraintAxis.Vertical; stackView.Spacing = 10; stackView.Distribution = UIStackViewDistribution.FillProportionally; cameraButton = new UIButton(new CGRect(0, 0, View.Bounds.Width / 2, View.Bounds.Width / 2)); cameraButton.SetTitle("Capture a new photo", UIControlState.Normal); cameraButton.SetTitleColor(UIColor.Black, UIControlState.Normal); cameraButton.Layer.BorderWidth = 1; cameraButton.Layer.CornerRadius = 3; cameraButton.Layer.BorderColor = UIColor.Black.CGColor; cameraButton.BackgroundColor = UIColor.White; cameraButton.TouchUpInside += (sender, e) => { pickerController.SourceType = UIImagePickerControllerSourceType.Camera; pickerController.MediaTypes = UIImagePickerController.AvailableMediaTypes(UIImagePickerControllerSourceType.Camera); PresentViewController(pickerController, true, null); }; imageButton = new UIButton(new CGRect(0, 0, View.Bounds.Width / 2, View.Bounds.Width / 2)); imageButton.SetTitle("Choose from gallery", UIControlState.Normal); imageButton.SetTitleColor(UIColor.Black, UIControlState.Normal); imageButton.Layer.BorderWidth = 1; imageButton.Layer.CornerRadius = 3; imageButton.Layer.BorderColor = UIColor.Black.CGColor; imageButton.BackgroundColor = UIColor.White; imageButton.TouchUpInside += (sender, e) => { pickerController.SourceType = UIImagePickerControllerSourceType.PhotoLibrary; pickerController.MediaTypes = UIImagePickerController.AvailableMediaTypes(UIImagePickerControllerSourceType.PhotoLibrary); PresentViewController(pickerController, true, null); }; stackView.Center = View.Center; stackView.AddArrangedSubview(cameraButton); stackView.AddArrangedSubview(imageButton); View.Add(stackView); }
private void DidSelectActionItemAt(int index) { Console.WriteLine($"did select action {index}"); //before we present system image picker, we must update present button //because first responder will be dismissed _presentButton.Selected = false; if (_openedAsInputView) { _imagePicker.Release(); } switch (index) { case 0 when UIImagePickerController.IsSourceTypeAvailable(UIImagePickerControllerSourceType.Camera): { var vc = new UIImagePickerController { SourceType = UIImagePickerControllerSourceType.Camera, AllowsEditing = true }; var mediaTypes = UIImagePickerController.AvailableMediaTypes(UIImagePickerControllerSourceType.Camera); if (mediaTypes != null) { vc.MediaTypes = mediaTypes; } NavigationController?.VisibleViewController?.PresentViewController(vc, true, null); break; } case 1 when UIImagePickerController.IsSourceTypeAvailable( UIImagePickerControllerSourceType.PhotoLibrary): { var vc = new UIImagePickerController { SourceType = UIImagePickerControllerSourceType.PhotoLibrary }; NavigationController?.VisibleViewController?.PresentViewController(vc, true, null); break; } } }
public override void ViewDidLoad() { base.ViewDidLoad(); // Perform any additional setup after loading the view, typically from a nib. btnRecognize.SetTitle("Select an Image", UIControlState.Normal); btnRecognize.TouchUpInside += delegate { var imagePicker = new UIImagePickerController { SourceType = UIImagePickerControllerSourceType.PhotoLibrary }; imagePicker.Delegate = this; PresentViewController(imagePicker, true, null); }; }
public override bool IsAvailable( ) { // get the permission settings AVAuthorizationStatus authStatus = AVCaptureDevice.GetAuthorizationStatus(AVMediaType.Video); // see if there's even a camera ON the device bool isTypeAvailable = UIImagePickerController.IsSourceTypeAvailable(UIImagePickerControllerSourceType.Camera); // if there IS a camera, and the permission is allowed or notdetermined, then yes, it's available. if (isTypeAvailable == true && (authStatus == AVAuthorizationStatus.Authorized || authStatus == AVAuthorizationStatus.NotDetermined)) { return(true); } // otherwise it isn't. return(false); }
void ShowPhotoPickerOptions() { // If the device (such as the simulator) doesn't have a camera, don't present that option. if (!UIImagePickerController.IsSourceTypeAvailable(UIImagePickerControllerSourceType.Camera)) { OnActionSheetDismissed(null, 0); return; } sheet = new UIActionSheet("Aircraft Photo"); sheet.AddButton("Choose Photo"); sheet.AddButton("Take Photo"); sheet.Delegate = new PhotoActionSheetDelegate(this); sheet.ShowFrom(PhotoRect, this, true); }
public void FinishedPickingMedia(UIImagePickerController picker, NSDictionary info) { var selectedImage = (UIImage)info [UIImagePickerController.OriginalImage]; var imageUrl = GetImageUrl(); if (selectedImage != null && selectedImageCellIndex.HasValue && imageUrl != null) { var index = selectedImageCellIndex.Value; var indexPath = NSIndexPath.FromRowSection(index, 0); var cell = (ImageFieldTableViewCell)TableView.CellAt(indexPath); var imageData = selectedImage.AsJPEG(0.8f); imageData?.Save(imageUrl, atomically: true); cell.AssetView.Image = selectedImage; cell.ImageInput.Value = imageUrl; } picker.DismissViewController(true, null); }
partial void SelectButton_TouchUpInside(UIButton sender) { imagePickerController = new UIImagePickerController(); imagePickerController.Delegate = this; imagePickerController.SourceType = UIImagePickerControllerSourceType.PhotoLibrary; imagePickerController.MediaTypes = UIImagePickerController.AvailableMediaTypes(UIImagePickerControllerSourceType.PhotoLibrary); //https://developer.xamarin.com/recipes/ios/media/video_and_photos/choose_a_photo_from_the_gallery/ imagePickerController.FinishedPickingMedia += Handle_FinishedPickingMedia; imagePickerController.Canceled += Handle_Canceled; if (NavigationController != null) { this.PresentViewController(imagePickerController, true, null); } }
void OpenScandit(object sender, EventArgs e) { if (!UIImagePickerController.IsSourceTypeAvailable(UIImagePickerControllerSourceType.Camera)) { new UIAlertView("Hey!!", "It seems that you don't have any camera available...\nThat's so sad... :(", null, "Let me cry alone...", null).Show(); return; } var button = sender as UIBarButtonItem; KindOfScan kind = (KindOfScan)button.Tag; var scanditPicker = new SIBarcodePicker(KeysAndTokens.ScanditApi.ScanditKey); scanditPicker.OverlayController.Delegate = new ScanditDelegate(this, kind); NavigationController.PushViewController(scanditPicker, true); scanditPicker.StartScanning(); }
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); }
void OnNewPostClicked(object sender, EventArgs e) { // Shows the user options for selecting an image to post string alertTitle = "How do you want to get your photo?"; UIAlertController picMethod = UIAlertController.Create(alertTitle, null, UIAlertControllerStyle.ActionSheet); picMethod.ModalPresentationStyle = UIModalPresentationStyle.Popover; UIPopoverPresentationController popPresenter = picMethod.PopoverPresentationController; if (popPresenter != null) { popPresenter.BarButtonItem = NavigationItem.RightBarButtonItem; } string takePhotoButton = "Take Photo"; UIAlertAction takePhoto = UIAlertAction.Create(takePhotoButton, UIAlertActionStyle.Default, action => { var imagePicker = new UIImagePickerController(); imagePicker.WeakDelegate = this; imagePicker.SourceType = UIImagePickerControllerSourceType.Camera; PresentViewController(imagePicker, true, null); }); string uploadButton = "Upload Photo"; UIAlertAction uploadPhoto = UIAlertAction.Create(uploadButton, UIAlertActionStyle.Default, action => { var imagePicker = new UIImagePickerController(); imagePicker.WeakDelegate = this; imagePicker.SourceType = UIImagePickerControllerSourceType.PhotoLibrary; PresentViewController(imagePicker, true, null); }); string selectButton = "Select from CloudKit"; UIAlertAction selectExisting = UIAlertAction.Create(selectButton, UIAlertActionStyle.Default, action => { // TODO: second param mast be null https://trello.com/c/PRQIGaTd PerformSegue("selectExisting", new NSObject()); }); UIAlertAction cancel = UIAlertAction.Create("Cancel", UIAlertActionStyle.Cancel, null); picMethod.AddAction(takePhoto); picMethod.AddAction(uploadPhoto); picMethod.AddAction(selectExisting); picMethod.AddAction(cancel); PresentViewController(picMethod, 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); } }
private void ChooseFromLibraryFunction() { if (!UIImagePickerController.IsSourceTypeAvailable(UIImagePickerControllerSourceType.PhotoLibrary)) { alertView = new UIAlertView("SnagR Upload Photos APP", "Sorry, you cannot select pictures with your device", new UIAlertViewDelegate(), "OK"); alertView.Show(); return; } imagePicker.SourceType = UIImagePickerControllerSourceType.PhotoLibrary; imagePicker.MediaTypes = UIImagePickerController.AvailableMediaTypes(UIImagePickerControllerSourceType.PhotoLibrary); imagePicker.FinishedPickingMedia += Handle_FinishedPickingMedia; imagePicker.Canceled += Handle_Canceled; this.PresentModalViewController(imagePicker, true); }
public override void ViewDidLoad() { base.ViewDidLoad(); // Configure UI CameraButton.Enabled = UIImagePickerController.IsSourceTypeAvailable(UIImagePickerControllerSourceType.Camera); GalleryButton.Enabled = UIImagePickerController.IsSourceTypeAvailable(UIImagePickerControllerSourceType.SavedPhotosAlbum); // Load the ML model var bundle = NSBundle.MainBundle; var assetPath = bundle.GetUrlForResource("MNISTClassifier", "mlmodelc"); var mlModel = MLModel.FromUrl(assetPath, out NSError mlErr); var model = VNCoreMLModel.FromMLModel(mlModel, out NSError vnErr); // Initialize RectangleRequest = new VNDetectRectanglesRequest(HandleRectangles); ClassificationRequest = new VNCoreMLRequest(model, HandleClassification); }
public override void FinishedPickingImage(UIImagePickerController picker, UIImage image, NSDictionary editingInfo) { //TODO: Add some logic that could return image from here. UIImage pickedImage; picker.DismissModalViewController(true); if (editingInfo[UIImagePickerController.EditedImage] != null) { pickedImage = editingInfo[UIImagePickerController.EditedImage] as UIImage; } else { pickedImage = editingInfo[UIImagePickerController.OriginalImage] as UIImage; } Models.UIImageModel newDataModel = new Models.UIImageModel(); newDataModel.base64String = pickedImage.AsJPEG().GetBase64EncodedString(NSDataBase64EncodingOptions.None); imagePicked(this, newDataModel); }
public async Task <byte[]> CapturePhotoAsync() { _imageTask = new TaskCompletionSource <byte[]>(); _imagePicker = new UIImagePickerController(); _imagePicker.PrefersStatusBarHidden(); _imagePicker.SourceType = UIImagePickerControllerSourceType.Camera; _imagePicker.FinishedPickingMedia += OnCaptureComplete; _imagePicker.Canceled += OnCaptureCancelled; StartCapture(); var imageBytes = await _imageTask.Task; return(imageBytes); }
private void CallPopupForChooseImage() { _imagePicker = new UIImagePickerController(); // set our source to the photo library _imagePicker.SourceType = UIImagePickerControllerSourceType.PhotoLibrary; // set what media types _imagePicker.MediaTypes = UIImagePickerController.AvailableMediaTypes(UIImagePickerControllerSourceType.PhotoLibrary); _imagePicker.FinishedPickingMedia += Handle_FinishedPickingMedia; //Eventhandler cannot convert to EventHandler //imagePicker.SetCommand("FinishedPickingMedia", new RelayCommand<EventArgs>(Handle_FinishedPickingMedia)); _imagePicker.SetCommand("Canceled", new RelayCommand(() => { Handle_Canceled(); })); NavigationController.PresentModalViewController(_imagePicker, true); }
/// <summary> /// Initializes the camera. /// </summary> /// <param name="parent">Parent view controller.</param> /// <param name="callback">Callback once photo is taken</param> /// <param name="onCancel">On cancel action</param> /// <param name="cameraToUse">Camera to use.</param> private static void InitializeCamera(BaseViewController parent, Action <NSDictionary> callback, Action onCancel, UIImagePickerControllerCameraDevice cameraToUse) { _callback = callback; _onCancel = onCancel; Init(); picker.SourceType = UIImagePickerControllerSourceType.Camera; var cameraAvailable = UIImagePickerController.IsCameraDeviceAvailable(cameraToUse); if (cameraAvailable) { picker.CameraDevice = cameraToUse; parent.PresentViewController(picker, true, null); } else { parent.ShowAlert("The camera is unavailable", "No Camera"); } }
public bool OpenCameraView(object sender) { var controller = sender as UIViewController; if (controller == null) { return(false); } var cameraView = new UIImagePickerController() { SourceType = UIImagePickerControllerSourceType.Camera }; controller.PresentViewController(cameraView, true, null); return(true); }
/// <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, () => { }); }
public override void FinishedPickingMedia(UIImagePickerController picker, NSDictionary info) { var cb = _callback; _callback = null; picker.DismissViewController(true, (Action)null); cb(info); UIImage photo = info[UIImagePickerController.OriginalImage] as UIImage; var dir = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); string fileName = System.IO.Path.Combine(dir, "saved.jpg"); NSData data = photo.AsJPEG(); NSError err = null; data.Save(fileName, false, out err); }
private void SelectButton_TouchUpInside(object sender, EventArgs e) { // create a new picker controller imagePicker = new UIImagePickerController(); // set our source to the photo library imagePicker.SourceType = UIImagePickerControllerSourceType.PhotoLibrary; // set what media types imagePicker.MediaTypes = UIImagePickerController.AvailableMediaTypes(UIImagePickerControllerSourceType.PhotoLibrary); imagePicker.FinishedPickingMedia += Handle_FinishedPickingMedia; imagePicker.Canceled += Handle_Canceled; // show the picker PresentModalViewController(imagePicker, true); //UIPopoverController picc = new UIPopoverController(imagePicker); }
partial void GetImage_TouchUpInside(UIButton sender) { // create a new picker controller imagePicker = new UIImagePickerController(); // set our source to the photo library imagePicker.SourceType = UIImagePickerControllerSourceType.PhotoLibrary; // set what media types imagePicker.MediaTypes = UIImagePickerController.AvailableMediaTypes(UIImagePickerControllerSourceType.PhotoLibrary); imagePicker.FinishedPickingMedia += Handle_FinishedPickingMedia; imagePicker.Canceled += Handle_Canceled; // show the picker NavigationController.PresentModalViewController(imagePicker, true); //UIPopoverController picc = new UIPopoverController(imagePicker); }
private static void _OnCancelledPick(object sender, EventArgs e) { if (_picker.parentViewController != null) { _picker.parentViewController.DismissViewController(true, null); } else { UIApplication.deviceRootViewController.DismissViewController(true, null); } _picker = null; _popover = null; if (_mediaPickCancelledHandlers != null) { _mediaPickCancelledHandlers(null, EventArgs.Empty); } }
public void BringUpPhotoGallery() { var imagePicker = new UIImagePickerController { SourceType = UIImagePickerControllerSourceType.PhotoLibrary, MediaTypes = UIImagePickerController.AvailableMediaTypes(UIImagePickerControllerSourceType.PhotoLibrary) }; imagePicker.AllowsEditing = true; //Make sure we have the root view controller which will launch the photo gallery var window = UIApplication.SharedApplication.KeyWindow; var vc = window.RootViewController; while (vc.PresentedViewController != null) { vc = vc.PresentedViewController; } //Show the image gallery vc.PresentViewController(imagePicker, true, null); //call back for when a picture is selected and finished editing imagePicker.FinishedPickingMedia += (sender, e) => { UIImage originalImage = e.Info[UIImagePickerController.EditedImage] as UIImage; if (originalImage != null) { //Got the image now, convert it to byte array to send back up to the forms project var pngImage = originalImage.AsPNG(); byte[] myByteArray = new byte[pngImage.Length]; System.Runtime.InteropServices.Marshal.Copy(pngImage.Bytes, myByteArray, 0, Convert.ToInt32(pngImage.Length)); MessagingCenter.Send <byte[]>(myByteArray, "ImageSelected"); } //Close the image gallery on the UI thread Device.BeginInvokeOnMainThread(() => { vc.DismissViewController(true, null); }); }; //Cancel button callback from the image gallery imagePicker.Canceled += (sender, e) => vc.DismissViewController(true, null); }