public void GetImageAsync(Action<MediaFile> imageData, bool fromCamera = true) { OnImageData = imageData; var context = Forms.Context as MainActivity; var picker = new MediaPicker(context); if (!picker.IsCameraAvailable) Console.WriteLine("No camera!"); else { Intent intent = null; if (fromCamera) { intent = picker.GetTakePhotoUI(new StoreCameraMediaOptions { Name = string.Format("vDoers_{0}.jpg", DateTime.Now.Ticks), Directory = "vDoersCamera" }); } else { intent = picker.GetPickPhotoUI(); } context.OnActvitiResultCallback -= OnActvitiResultCallback; context.OnActvitiResultCallback += OnActvitiResultCallback; context.StartActivityForResult(intent, 1); } }
/* Snippet 2 Start */ /// <summary> /// Startet ein Intent zum Aufnehmen eines Fotos /// </summary> /// <param name="sender">Button sender</param> /// <param name="eventArgs">Event Arguments</param> private void TakeAPicture(object sender, EventArgs eventArgs) { var picker = new MediaPicker(this); var intent = picker.GetTakePhotoUI(new StoreCameraMediaOptions { Name = "test.jpg", Directory = "CameraAppDemo" }); StartActivityForResult(intent, 1); }
public async Task<Stream> TakePhoto() { var picker = new MediaPicker(Application.Context); var intent = picker.GetTakePhotoUI(new StoreCameraMediaOptions()); intent.SetFlags(ActivityFlags.NewTask); Application.Context.StartActivity(intent); return null; }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); var picker = new MediaPicker(this); var intent = picker.GetTakePhotoUI( new StoreCameraMediaOptions { Name = "test.jpg", Directory = "photos" }); StartActivityForResult(intent, 1); }
public void TakePhoto() { var picker = new MediaPicker(_context); if (!picker.IsCameraAvailable) return; var fileName = Guid.NewGuid() + ".jpg"; var intent = picker.GetTakePhotoUI(new StoreCameraMediaOptions { Name = fileName, Directory = null }); _context.StartActivityForResult(intent, IntentConstants.TakePhoto); }
protected override void OnCreate (Bundle bundle) { base.OnCreate (bundle); var picker = new MediaPicker (this); if (!picker.IsCameraAvailable) System.Console.WriteLine ("No camera!"); else { var intent = picker.GetTakePhotoUI (new StoreCameraMediaOptions { Name = "test.jpg", Directory = "CouchbaseConnect", }); StartActivityForResult (intent, 0); } }
void PresentCamera () { var picker = new MediaPicker(); MediaPickerController controller = picker.GetTakePhotoUI (new StoreCameraMediaOptions { Name = "scavengerhunt.jpg", Directory = "CouchbaseConnect" }); PresentViewController (controller, true, null); controller.GetResultAsync().ContinueWith (t => { // Dismiss the UI yourself controller.DismissViewController (true, () => { try { if (t.Status != TaskStatus.Canceled) { MediaFile file = t.Result; ((CameraContentPage)this.Element).Captured = file.Path; } } catch(AggregateException aggX) { if(aggX.InnerException is TaskCanceledException) { //nothing Console.WriteLine("Task Cancelled"); } else { throw; } } }); }, TaskScheduler.FromCurrentSynchronizationContext()); ((CameraContentPage)this.Element).IsPresented = false; }
private void TakePhoto() { var picker = new MediaPicker(this); if (!picker.IsCameraAvailable) { Console.WriteLine("No Camera :("); return; } var options = new StoreCameraMediaOptions { Name = "temp.jpg", Directory = "flashcast" }; var intent = picker.GetTakePhotoUI(options); StartActivityForResult(intent, 1); }
public void GetImageAsync(Action<MediaFile> imageData, bool fromCamera = true) { var picker = new MediaPicker(); MediaPickerController controller = null; if (fromCamera) { controller = picker.GetTakePhotoUI(new StoreCameraMediaOptions { Name = string.Format("vDoers_{0}.jpg", DateTime.Now.Ticks), Directory = "vDoersCamera" }); } else { controller = picker.GetPickPhotoUI(); } var window = UIApplication.SharedApplication.KeyWindow; var vc = window.RootViewController; if (vc != null) { // vc = vc.PresentedViewController; vc.PresentViewController(controller, true, null); } controller.GetResultAsync().ContinueWith(t => { // Dismiss the UI yourself controller.DismissViewController(true, () => { if (imageData != null) { imageData(t.Result); } }); }, TaskScheduler.FromCurrentSynchronizationContext()); }
public override async void ViewWillAppear (bool animated) { base.ViewWillAppear (animated); if (fileName == "") { fileName = "in-progress"; var picker = new MediaPicker (); // new MediaPicker (this); on Android if (!picker.IsCameraAvailable || !picker.PhotosSupported) Console.WriteLine ("No camera!"); else { var options = new StoreCameraMediaOptions { Name = DateTime.Now.ToString("yyyyMMddHHmmss"), Directory = "MediaPickerSample" }; #if !VISUALSTUDIO #region new style pickerController = picker.GetTakePhotoUI (options); PresentViewController (pickerController, true, null); var pickerTask = pickerController.GetResultAsync (); await pickerTask; // We need to dismiss the controller ourselves await DismissViewControllerAsync (true); // woot! async-ified iOS method // User canceled or something went wrong if (pickerTask.IsCanceled || pickerTask.IsFaulted) return; // We get back a MediaFile MediaFile media = pickerTask.Result; fileName = media.Path; PhotoImageView.Image = new UIImage (fileName); SavePicture(fileName); #endregion #else #region old style (deprecated) var t = picker.TakePhotoAsync (options); //.ContinueWith (t => { await t; if (t.IsCanceled) { Console.WriteLine ("User canceled"); fileName = "cancelled"; //InvokeOnMainThread(() =>{ NavigationController.PopToRootViewController(false); //}); return; } Console.WriteLine (t.Result.Path); fileName = t.Result.Path; //InvokeOnMainThread(() =>{ PhotoImageView.Image = new UIImage (fileName); //}); SavePicture(fileName); //}); #endregion #endif } } else if (fileName == "cancelled") { NavigationController.PopToRootViewController (true); } else { // populate screen with existing item PhotoImageView.Image = new UIImage (fileName); LocationText.Text = location; } var locator = new Geolocator { DesiredAccuracy = 50 }; // new Geolocator (this) { ... }; on Android var position = await locator.GetPositionAsync (timeout: 10000); //.ContinueWith (p => { Console.WriteLine ("Position Latitude: {0}", position.Latitude); Console.WriteLine ("Position Longitude: {0}", position.Longitude); location = string.Format("{0},{1}", position.Latitude, position.Longitude); LocationText.Text = location; }
public override async void ViewWillAppear (bool animated) { base.ViewWillAppear (animated); if (fileName == "") { fileName = "in-progress"; var picker = new MediaPicker (); // new MediaPicker (this); on Android if (!picker.IsCameraAvailable || !picker.PhotosSupported) Console.WriteLine ("No camera!"); else { var options = new StoreCameraMediaOptions { Name = DateTime.Now.ToString("yyyyMMddHHmmss"), Directory = "MediaPickerSample" }; pickerController = picker.GetTakePhotoUI (options); PresentViewController (pickerController, true, null); MediaFile media; try { var pickerTask = pickerController.GetResultAsync (); await pickerTask; // User canceled or something went wrong if (pickerTask.IsCanceled || pickerTask.IsFaulted) { fileName = ""; return; } media = pickerTask.Result; fileName = media.Path; // We need to dismiss the controller ourselves await DismissViewControllerAsync (true); // woot! async-ified iOS method } catch(AggregateException ae) { fileName = ""; Console.WriteLine("Error while huh", ae.Message); } catch(Exception e) { fileName = ""; Console.WriteLine("Error while cancelling", e.Message); } if (String.IsNullOrEmpty (fileName)) { await DismissViewControllerAsync (true); } else { PhotoImageView.Image = new UIImage (fileName); SavePicture(fileName); } } } else if (fileName == "cancelled") { NavigationController.PopToRootViewController (true); } else { // populate screen with existing item PhotoImageView.Image = FileExists(fileName) ? new UIImage (fileName) : null; LocationText.Text = location; } var locator = new Geolocator { DesiredAccuracy = 50 }; var position = await locator.GetPositionAsync ( new CancellationToken(), false); Console.WriteLine ("Position Latitude: {0}", position.Latitude); Console.WriteLine ("Position Longitude: {0}", position.Longitude); location = string.Format("{0},{1}", position.Latitude, position.Longitude); LocationText.Text = location; }
private void TakePic(int requestCode) { var activity = Forms.Context as Activity; var picker = new MediaPicker(activity); var rnd = new Random(); var randomInt = rnd.Next(1, 99999); var intent = picker.GetTakePhotoUI(new StoreCameraMediaOptions { Name = randomInt + "_accidentPicture.jpg", Directory = "AutoResolve" }); activity.StartActivityForResult(intent, requestCode); }
void imgFoto_Click(object sender, EventArgs e) { selectedFoto = (ImageView) sender; /*Intent intent = new Intent(); intent.SetType("image/*"); intent.SetAction(Intent.ActionGetContent); this.StartActivityForResult(Intent.CreateChooser(intent, "Seleccionar Imagen"), 0);*/ var picker = new MediaPicker (this); if (!picker.IsCameraAvailable) { alert.SetMessage("No se encontró la cámara"); alert.Show(); } else { var intent = picker.GetTakePhotoUI (new StoreCameraMediaOptions { Name = "text.jpg"/*, Directory = "Alertapp"*/ }); StartActivityForResult (intent, 1); } }
private void createTakePhotoBtn(Section pictureS) { var takePic = new StyledStringElement("Take Pictures",""); takePic.Tapped += ()=>{ var picker = new MediaPicker (); if(!picker.IsCameraAvailable){ //Console.Out.WriteLine("Camera is not available !"); }else{ try{ var imgControl = picker.GetTakePhotoUI (new StoreCameraMediaOptions{ Name = DateTime.Now.ToString() + ".jpg", Directory = _directoyName+"/photos", }); this.PresentViewController(imgControl,true,null); imgControl.GetResultAsync().ContinueWith(t=>{ this.DismissViewController(true,()=>{ if (t.IsCanceled || t.IsFaulted){ return; } //var url = new NSUrl(t.Result.Path); imageList.Add(t.Result.Path); //Console.Out.WriteLine(url); pictureS.Add(new StringElement ("Picture", ()=>{ createImageViewScreen(t.Result.Path,pictureS); })); this.Root.Reload(pictureS,UITableViewRowAnimation.None); }); },TaskScheduler.FromCurrentSynchronizationContext()); }catch(OperationCanceledException){ //Console.Out.WriteLine("Camera canceled"); } } }; takePic.TextColor = UIColor.Red; pictureS.Add(takePic); }
void ShowCamera() { CheckDropboxLinked(); var picker = new MediaPicker(); MediaPickerController controller = picker.GetTakePhotoUI (new StoreCameraMediaOptions { Name = "latest.jpg", Directory = "Shooter" }); // On iPad, you'll use UIPopoverController to present the controller PresentViewController (controller, true, null); controller.GetResultAsync().ContinueWith (t => { controller.DismissViewControllerAsync(true).ContinueWith( (t2) => { // Move to Dropbox. if (t.Status == TaskStatus.RanToCompletion) { MediaFile photoFile = t.Result; UIImage originalImage = new UIImage(photoFile.Path); NSData imageData = ResizeImage(originalImage, 0.3f).AsJPEG(); DBPath path = new DBPath(string.Format("{0:yyyy-MM-dd-HH-mm-ss}.jpg", DateTime.Now)); DBError err; DBFile file = DBFilesystem.SharedFilesystem.CreateFile(path, out err); file.WriteDataAsync(imageData).ContinueWith(t3 => { file.Close(); }); Task.Run(() => { System.Threading.Thread.Sleep(1000); }).ContinueWith((t3) => { ShowCamera(); }, TaskScheduler.FromCurrentSynchronizationContext()); } }); }, TaskScheduler.FromCurrentSynchronizationContext()); }
protected override async void OnResume () { base.OnResume (); int itemId = Intent.GetIntExtra(ShareItemIdExtraName, 0); if(itemId > 0) { shareItem = App.Database.GetItem(itemId); fileName = shareItem.ImagePath; System.Console.WriteLine("Image path: " + fileName); Bitmap b = BitmapFactory.DecodeFile (fileName); // Display the bitmap photoImageView.SetImageBitmap (b); locationText.Text = shareItem.Location; return; } if (fileName == "") { fileName = "in-progress"; var picker = new MediaPicker (this); // new MediaPicker (); on iOS if (!picker.IsCameraAvailable) System.Console.WriteLine ("No camera!"); else { var options = new StoreCameraMediaOptions { Name = DateTime.Now.ToString("yyyyMMddHHmmss"), Directory = "MediaPickerSample" }; #if !VISUALSTUDIO #region new style if (!picker.IsCameraAvailable || !picker.PhotosSupported) { ShowUnsupported(); return; } Intent intent = picker.GetTakePhotoUI (options); StartActivityForResult (intent, 1); #endregion #else #region old style (deprecated) var t = picker.TakePhotoAsync (options); await t; if (t.IsCanceled) { System.Console.WriteLine ("User canceled"); fileName = "cancelled"; // TODO: return to main screen StartActivity(typeof(MainScreen)); return; } System.Console.WriteLine (t.Result.Path); fileName = t.Result.Path; fileNameThumb = fileName.Replace(".jpg", "_thumb.jpg"); Bitmap b = BitmapFactory.DecodeFile (fileName); RunOnUiThread (() => { // Display the bitmap photoImageView.SetImageBitmap (b); // Cleanup any resources held by the MediaFile instance t.Result.Dispose(); }); var boptions = new BitmapFactory.Options {OutHeight = 128, OutWidth = 128}; var newBitmap = await BitmapFactory.DecodeFileAsync (fileName, boptions); var @out = new System.IO.FileStream(fileNameThumb, System.IO.FileMode.Create); newBitmap.Compress(Android.Graphics.Bitmap.CompressFormat.Jpeg, 90, @out); //}); #endregion #endif } } try { var locator = new Geolocator (this) { DesiredAccuracy = 50 }; // new Geolocator () { ... }; on iOS var position = await locator.GetPositionAsync (timeout: 10000); System.Console.WriteLine ("Position Latitude: {0}", position.Latitude); System.Console.WriteLine ("Position Longitude: {0}", position.Longitude); location = string.Format("{0},{1}", position.Latitude, position.Longitude); locationText.Text = location; } catch (Exception e) { System.Console.WriteLine ("Position Exception: " + e.Message); } }
private void MakePhoto_Click(object sender, EventArgs e) { try { var picker = new MediaPicker(this); if (!picker.IsCameraAvailable || !picker.PhotosSupported) { ShowUnsupported(); return; } var store = new StoreCameraMediaOptions { Directory = "Ersh", Name = string.Format("ersh_{0}.jpg", DateTime.Now.Ticks + new Random().Next()) }; var intent = picker.GetTakePhotoUI(store); this.StartActivityForResult(intent, 2); } catch (Exception exception) { GaService.TrackAppException(this.Class, "MakePhoto_Click", exception, false); } }
protected override void OnCreate (Bundle bundle) { base.OnCreate (bundle); SetContentView (Resource.Layout.Main); Button videoButton = FindViewById<Button> (Resource.Id.takeVideoButton); videoButton.Click += delegate { // MediaPicker is the class used to invoke the // camera and gallery picker for selecting and // taking photos and videos var picker = new MediaPicker (this); // We can check to make sure the device has a camera // and supports dealing with video. if (!picker.IsCameraAvailable || !picker.VideosSupported) { ShowUnsupported(); return; } // The GetTakeVideoUI method returns an Intent to start // the native camera app to record a video. Intent intent = picker.GetTakeVideoUI (new StoreVideoOptions { Name = "MyVideo", Directory = "MyVideos", DesiredLength = TimeSpan.FromSeconds (10) }); StartActivityForResult (intent, 1); }; Button photoButton = FindViewById<Button> (Resource.Id.takePhotoButton); photoButton.Click += delegate { var picker = new MediaPicker (this); if (!picker.IsCameraAvailable || !picker.PhotosSupported) { ShowUnsupported(); return; } Intent intent = picker.GetTakePhotoUI (new StoreCameraMediaOptions { Name = "test.jpg", Directory = "MediaPickerSample" }); StartActivityForResult (intent, 2); }; Button pickVideoButton = FindViewById<Button> (Resource.Id.pickVideoButton); pickVideoButton.Click += delegate { var picker = new MediaPicker (this); if (!picker.VideosSupported) { ShowUnsupported(); return; } // The GetPickVideoUI() method returns an Intent to start // the native gallery app to select a video. Intent intent = picker.GetPickVideoUI(); StartActivityForResult (intent, 1); }; Button pickPhotoButton = FindViewById<Button> (Resource.Id.pickPhotoButton); pickPhotoButton.Click += delegate { var picker = new MediaPicker (this); if (!picker.PhotosSupported) { ShowUnsupported(); return; } Intent intent = picker.GetPickPhotoUI(new StoreCameraMediaOptions { Name = "selected.jpg", Directory = "MediaPickerSample" }); StartActivityForResult (intent, 2); }; }
private void MakePhoto_Click(object sender, EventArgs e) { var picker = new MediaPicker(Activity); if (!picker.IsCameraAvailable || !picker.PhotosSupported) { ShowUnsupported(); return; } var store = new StoreCameraMediaOptions() { Directory = "Yoursh", Name = "photo1.jpg" }; var intent = picker.GetTakePhotoUI(store); StartActivityForResult(intent, 2); }
protected override async void OnResume () { base.OnResume (); int itemId = Intent.GetIntExtra(ShareItemIdExtraName, 0); if(itemId > 0) { shareItem = App.Database.GetItem(itemId); fileName = shareItem.ImagePath; Console.WriteLine ("Image path: {0}", fileName); Bitmap b = BitmapFactory.DecodeFile (fileName); // Display the bitmap photoImageView.SetImageBitmap (b); locationText.Text = shareItem.Location; return; } if (string.IsNullOrEmpty (fileName)) { fileName = "in-progress"; var picker = new MediaPicker (this); if (!picker.IsCameraAvailable) { Console.WriteLine ("No camera!"); } else { var options = new StoreCameraMediaOptions { Name = DateTime.Now.ToString ("yyyyMMddHHmmss"), Directory = "MediaPickerSample" }; if (!picker.IsCameraAvailable || !picker.PhotosSupported) { ShowUnsupported(); return; } Intent intent = picker.GetTakePhotoUI (options); StartActivityForResult (intent, 1); } } else { SetImage (); } try { var locator = new Geolocator (this) { DesiredAccuracy = 50 }; var position = await locator.GetPositionAsync (10000); Console.WriteLine ("Position Latitude: {0}", position.Latitude); Console.WriteLine ("Position Longitude: {0}", position.Longitude); location = string.Format ("{0},{1}", position.Latitude, position.Longitude); locationText.Text = location; } catch (Exception e) { Console.WriteLine ("Position Exception: {0}", e.Message); } }
public EditVisitorView(EditVisitorViewController parent) { BackgroundColor = UIColor.FromRGB(239, 239, 244); image = new UIButton { Frame = new RectangleF(0, 0, 150, 150), TintColor = UIColor.White, Layer = { CornerRadius = 75, MasksToBounds = true, } }; image.SetTitle("Change photo", UIControlState.Normal); image.ImageView.ContentMode = UIViewContentMode.ScaleAspectFill;; image.SetImage(Theme.UserImageDefaultLight.Value,UIControlState.Normal); image.TouchUpInside += async (sender, args) => { try { var picker = new MediaPicker(); var controller = picker.GetTakePhotoUI(new StoreCameraMediaOptions { Name = "test.jpg", Directory = "MediaPickerSample" }); //var popupver = new UIPopoverController(controller); //popupver.PresentFromRect(image.Frame,this, UIPopoverArrowDirection.Any, true); parent.PresentViewController(controller, true, null); var result = await controller.GetResultAsync(); var i = UIImage.FromFile(result.Path).ResizeImage(380,380); NSError error; i.AsJPEG().Save(result.Path, NSDataWritingOptions.FileProtectionNone, out error); Console.WriteLine("Result came back"); Console.WriteLine(result); Console.WriteLine(result.Path); var picture = new VisitorPicture { Content = File.ReadAllBytes(result.Path), PictureType = PictureType.Small, }; var picture2 = new VisitorPicture { Content = File.ReadAllBytes(result.Path), PictureType = PictureType.Big, }; image.SetImage(UIImage.FromFile(result.Path) ?? Theme.UserImageDefaultLight.Value, UIControlState.Normal); Visitor.ClearPhotos(); Visitor.AddPicture(picture); Visitor.AddPicture(picture2); } catch (Exception ex) { Console.WriteLine(ex); } finally { parent.DismissViewController(true,null); } //popupver.Dismiss(true); }; AddSubview(image); dvc = new DialogViewController(new RootElement("Visitor") { new Section("Visitor") { (firstName = new EntryElement("First name", "John","")), (lastName = new EntryElement("Last name","Apleseed","")), (idNumber = new EntryElement("Id number","123456","")), (email = new EntryElement("Email", "*****@*****.**","")), (company = new EntryElement("Organization/ Company","MyCompany","")), (title = new EntryElement("Proffesional Title","CEO","")) } }) { TableView = { SectionHeaderHeight = 0, BackgroundColor = UIColor.White, Layer = { CornerRadius = 5, MasksToBounds = true } } }; this.AddSubview(dvc.View); parent.AddChildViewController(dvc); }