public override void ViewDidLoad() { base.ViewDidLoad (); buttonLocation.TouchUpInside += (sender, e) => { var locator = new Geolocator { DesiredAccuracy = 50 }; locator.GetPositionAsync (timeout: 10000).ContinueWith (t => { var text = String.Format("Lat: {0}, Long: {0}", t.Result.Latitude, t.Result.Longitude); InvokeOnMainThread(() => LabelLocation.Text = text); }); }; buttonPicture.TouchUpInside += (sender, e) => { var camera = new MediaPicker (); if (!camera.IsCameraAvailable) { Console.WriteLine("Camera unavailable!"); return; } var opts = new StoreCameraMediaOptions { Name = "test.jpg", Directory = "MiniHackDemo" }; camera.TakePhotoAsync (opts).ContinueWith (t => { if (t.IsCanceled) return; InvokeOnMainThread(() => imagePhoto.Image = UIImage.FromFile(t.Result.Path)); }); }; }
public void TakeAndStorePhoto(Action<string> onPhotoTaken) { var picker = new MediaPicker(); if (!picker.IsCameraAvailable || !picker.PhotosSupported) { MvxTrace.Trace(MvxTraceLevel.Diagnostic, "Photo taking not available"); return; } var photoName = string.Format("Sphero{0:yyyyMMddHHmmss}.jpg", DateTime.Now); picker.TakePhotoAsync(new StoreCameraMediaOptions { Name = photoName, Directory = PictureFolder }) .ContinueWith(t => { if (t.IsCanceled) return; #warning Code to do... //var file = this.GetService<IMvxSimpleFileStoreService>(); //file.WriteFile(t.Result.Path, stream => t.Result.GetStream().CopyTo(stream)); //file.WriteFile("Test.txt", "Some text"); onPhotoTaken(t.Result.Path); }); }
public async System.Threading.Tasks.Task<CameraFile> TakePhotoAsync () { CameraFile result = new CameraFile (); try { var picker = new MediaPicker (Platform_Android.MainActivity); if (!picker.IsCameraAvailable) { result.Exception = new ArgumentException ("No camera available."); } else { try { var file = await picker.TakePhotoAsync (new StoreCameraMediaOptions { Name = "test.jpg", Directory = "PoSDB" }); File.WriteAllBytes (file.Path + "_small.jpg", ResizeImageAndroid (imageData: File.ReadAllBytes (file.Path))); result.Stream = () => new MemoryStream (File.ReadAllBytes (file.Path + "_small.jpg")); } catch (OperationCanceledException) { result.IsCancelled = true; } } } catch (Exception ex) { result.Exception = ex; } return result; }
public override void ViewDidLoad () { base.ViewDidLoad (); var picker = new MediaPicker (); this.bntCamera.TouchUpInside += (sender, e) => { if (!picker.IsCameraAvailable) lblSuccess.Text = "No camera!"; else { picker.TakePhotoAsync (new StoreCameraMediaOptions { Name = "test.jpg", Directory = "MediaPickerSample" }).ContinueWith (t => { if (t.IsCanceled) { lblSuccess.Text = "User cancelled"; return; } lblSuccess.Text = "Photo succeeded"; Console.WriteLine(t.Result.Path); }, TaskScheduler.FromCurrentSynchronizationContext()); } }; }
private void ButtonSendAttachmentEmail_Click(object sender, EventArgs eventArgs) { var picker = new MediaPicker(Application.Context); var intent = picker.GetPickPhotoUI(); StartActivityForResult(intent, SelectPhoto); }
async partial void OnTakePhoto() { var picker = new MediaPicker(Forms.Context); if (!picker.IsCameraAvailable) await DisplayAlert("Error", "No Camera Available!", "OK", null); else { var intent = new Intent( Forms.Context, typeof(PhotoApp.Android.PhotoActivity)); var context = Forms.Context; Action<string> cb = null; cb = (file) => { PhotoApp.Android.PhotoActivity.ImageComplete -= cb; if (string.IsNullOrEmpty(file)) { Image image = new Image() { Source = new FileImageSource { File = file } }; this.Content = image; } }; PhotoApp.Android.PhotoActivity.ImageComplete += cb; context.StartActivity(intent); } }
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); } }
/// <summary> /// Event handler when the user clicks the Take a Photo button /// </summary> /// <param name='sender'> /// Sender /// </param> partial void takePhotoBtnClicked (MonoTouch.Foundation.NSObject sender) { Console.WriteLine("takePhotoBtnClicked"); picker = new MediaPicker (); // Check if a camera is available and photos are supported on this device if (!picker.IsCameraAvailable || !picker.PhotosSupported) { ShowUnsupported(); return; } // Call TakePhotoAsync, which gives us a Task<MediaFile> picker.TakePhotoAsync (new StoreCameraMediaOptions { Name = "test.jpg", Directory = "MediaPickerSample" }) .ContinueWith (t => // Continue when the user has taken a photo { if (t.IsCanceled) // The user canceled return; // Show the photo the user took InvokeOnMainThread( delegate { UIImage image = UIImage.FromFile(t.Result.Path); this.imageView.Image = image; }); }); }
protected override void OnCreate (Bundle bundle) { base.OnCreate (bundle); // Set our view from the "main" layout resource SetContentView (Resource.Layout.Main); // Get our button from the layout resource, // and attach an event to it Button button = FindViewById<Button> (Resource.Id.myButton); TextView label = FindViewById<TextView> (Resource.Id.lblSuccess); button.Click += delegate { var picker = new MediaPicker (this); if (!picker.IsCameraAvailable) label.Text = "No camera!"; else { picker.TakePhotoAsync (new StoreCameraMediaOptions { Name = "test.jpg", Directory = "MediaPickerSample" }).ContinueWith (t => { if (t.IsCanceled) { label.Text = "User canceled"; return; } label.Text = "Photo succeeded"; Console.WriteLine (t.Result.Path); }, TaskScheduler.FromCurrentSynchronizationContext()); } }; }
public MediaPicker() { #if __IOS__ || WINDOWS_PHONE this.picker = new XamMediaPicker(); #elif __ANDROID__ this.picker = new XamMediaPicker(Forms.Context); #endif }
public void TakeAndStorePhoto(Action<string> onPhotoTaken) { var currentActivityService = this.GetService<IMvxAndroidCurrentTopActivity>(); var currentActivity = currentActivityService.Activity; var picker = new MediaPicker(currentActivity); if (!picker.IsCameraAvailable || !picker.PhotosSupported) { MvxTrace.Trace(MvxTraceLevel.Diagnostic, "Photo taking not available"); return; } var photoName = string.Format("Sphero{0:yyyyMMddHHmmss}.jpg", DateTime.Now); picker.TakePhotoAsync(new StoreCameraMediaOptions { Name = photoName, Directory = PictureFolder }) .ContinueWith(t => { if (t.IsCanceled) return; onPhotoTaken(t.Result.Path); }); }
public override void OnCreate (Bundle savedInstanceState) { base.OnCreate (savedInstanceState); assignmentViewModel = ServiceContainer.Resolve<AssignmentViewModel> (); photoViewModel = ServiceContainer.Resolve<PhotoViewModel> (); mediaPicker = new MediaPicker (Activity); }
private async Task<MediaFile> UseCamera(MediaPicker picker) { var fileName = DateTime.Now.Ticks + ".png"; return await picker.TakePhotoAsync(new StoreCameraMediaOptions { Directory = "temp", Name = fileName //DefaultCamera = CameraDevice.Rear }); }
/* 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 void TakePicture () { var activity = Forms.Context as Activity; var picker = new MediaPicker(activity); var intent = picker.GetPickPhotoUI (); activity.StartActivityForResult(intent, 1); }
private void ChoosePhoto_Click(object sender, EventArgs e) { var picker = new MediaPicker(Activity); if (!picker.PhotosSupported) { ShowUnsupported(); return; } var intent = picker.GetPickPhotoUI(); StartActivityForResult(intent, 2); }
public async void TakePicture () { var picker = new MediaPicker(); var mediaFile = await picker.TakePhotoAsync (new StoreCameraMediaOptions () { DefaultCamera = CameraDevice.Front, }); System.Diagnostics.Debug.WriteLine(mediaFile.Path); MessagingCenter.Send<IPhotoService, string>(this, "photoShot", mediaFile.Path); }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); // Set our view from the "main" layout resource SetContentView(Resource.Layout.Main); // Get our button from the layout resource, // and attach an event to it Button button = FindViewById<Button>(Resource.Id.buttonLocation); LabelLocation = FindViewById<TextView>(Resource.Id.locationLabel); image = FindViewById<ImageView>(Resource.Id.imagePhoto); button.Click += delegate { var locator = new Geolocator(this) { DesiredAccuracy = 50 }; locator.GetPositionAsync(timeout: 10000).ContinueWith(t => { var text = String.Format("Location : Lat: {0}, Long: {0}", t.Result.Latitude, t.Result.Longitude); this.RunOnUiThread(() => LabelLocation.Text = text); }); }; Button getimge = FindViewById<Button>(Resource.Id.buttonCamera); getimge.Click += delegate { var camera = new MediaPicker(this); if (!camera.IsCameraAvailable) { Console.WriteLine("Camera unavailable!"); return; } var opts = new StoreCameraMediaOptions { Name = "test.jpg", Directory = "MiniHackDemo" }; camera.TakePhotoAsync(opts).ContinueWith(t => { if (t.IsCanceled) return; using (var bmp = Android.Graphics.BitmapFactory.DecodeFile(t.Result.Path)) { this.RunOnUiThread(() => image.SetImageBitmap(bmp)); } }); }; }
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 async Task<Stream> PickPhoto() { var picker = new MediaPicker(Application.Context); var intent = picker.GetPickPhotoUI(); intent.SetFlags(ActivityFlags.NewTask); Application.Context.StartActivity(intent); return null; }
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; }
public static async Task<string> PathToVideoFromGallery (MediaPicker mediaPicker) { try{ if (!mediaPicker.PhotosSupported) { return null; } var mediaFile = await mediaPicker.PickVideoAsync (); return mediaFile.Path; }catch { return null; } }
void BtChooseImage_TouchUpInside(object sender, EventArgs e) { esStat.Reset (); var picker = new MediaPicker(); picker.TakePhotoAsync(new StoreCameraMediaOptions { Name = "emo.jpg", Directory = "EmotionDetector" }).ContinueWith (async t => { MediaFile file = t.Result; ivImage.Image = MaxResizeImage(UIImage.FromFile(file.Path), 640, 640); await _vm.Load (ivImage.Image.AsPNG().AsStream()); DrawRects (_vm.Emotions); }, TaskScheduler.FromCurrentSynchronizationContext()); }
public static async Task<string> PathToPictureFromCamera (MediaPicker mediaPicker) { try{ if (!mediaPicker.IsCameraAvailable || !mediaPicker.PhotosSupported) { return null; } var mediaFile = await mediaPicker.TakePhotoAsync (new StoreCameraMediaOptions {}); return mediaFile.Path; } catch { return null; } }
private async void addPhoto(bool takeNew) { //Capture photo file from view var picker = new Xamarin.Media.MediaPicker(); var options = new Xamarin.Media.StoreCameraMediaOptions(); var mediaFileSource = this.GetService <Core.Interfaces.IMediaFileSource>(); MediaFile mediaFile = null; try { mediaFile = await mediaFileSource.GetPhoto(takeNew); } catch { } if (mediaFile != null && !string.IsNullOrEmpty(mediaFile.Path)) { this.Dispatcher.BeginInvoke(() => { this.Photo = new System.Windows.Media.Imaging.BitmapImage(); this.Photo.SetSource(mediaFile.GetStream()); var photoBase64 = string.Empty; var wbmp = new System.Windows.Media.Imaging.WriteableBitmap(this.Photo); using (var ms = new System.IO.MemoryStream()) { wbmp.SaveJpeg(ms, 640, 480, 0, 60); photoBase64 = Convert.ToBase64String(ms.ToArray()); } this.ViewModel.AddPhoto(photoBase64); //Clean up! mediaFile.Dispose(); }); } }
public MediaPicker() { this.picker = new XamMediaPicker(); }
public MediaPicker(Android.Content.Context context) { this.picker = new XamMediaPicker(context); }
/// <summary> /// Event handler when the user clicks the Pick a Photo button /// </summary> /// <param name='sender'> /// Sender /// </param> partial void pickPhotoBtnClicked (MonoTouch.Foundation.NSObject sender) { Console.WriteLine("pickPhotoBtnClicked"); picker = new MediaPicker (); // Check if photos are supported on this device if (!picker.PhotosSupported) { ShowUnsupported(); return; } // Call PickPhotoAsync, which gives us a Task<MediaFile> picker.PickPhotoAsync () .ContinueWith (t => // Continue when the user has picked a photo { if (t.IsCanceled) // The user canceled return; // Show the photo the user selected InvokeOnMainThread( delegate { UIImage image = UIImage.FromFile(t.Result.Path); this.imageView.Image = image; }); }); }
public Task<MediaFile> GetPhoto(bool takeNew) { #if MONOANDROID var activity = this.GetService<Cirrious.MvvmCross.Droid.Interfaces.IMvxAndroidCurrentTopActivity>(); var picker = new MediaPicker(activity.Activity); #else var picker = new MediaPicker(); #endif if (takeNew) return picker.TakePhotoAsync(new StoreCameraMediaOptions()); else return picker.PickPhotoAsync(); }
public static void PictureFromGallery (MediaPicker picker, Action<MediaFile> callback) { if (!picker.PhotosSupported) { //ToDo: How to handle unsupported return; } picker.PickPhotoAsync().ContinueWith (t => { if(t.IsCanceled) return; callback(t.Result); }); }
void MediaChooser (object sender, UIButtonEventArgs e) { if (e.ButtonIndex == 1) { System.Console.WriteLine ("Camera"); var picker = new MediaPicker (); if (!picker.IsCameraAvailable) Console.WriteLine ("No camera!"); else { picker.TakePhotoAsync (new StoreCameraMediaOptions { Name = "test.jpg", Directory = "MediaPickerSample" }).ContinueWith (t => { if (t.IsCanceled) { Console.WriteLine ("User canceled"); return; } Console.WriteLine (t.Result.Path); imageView.Image = new UIImage(t.Result.Path); }, TaskScheduler.FromCurrentSynchronizationContext()); } } else if (e.ButtonIndex == 2) { System.Console.WriteLine ("Library"); var picker = new MediaPicker (); // new MediaPicker (this); on Android picker.PickPhotoAsync() .ContinueWith (t => { if (t.IsCanceled) { Console.WriteLine ("User canceled"); return; } Console.WriteLine (t.Result.Path); imageView.Image = new UIImage(t.Result.Path); }, TaskScheduler.FromCurrentSynchronizationContext()); } }
public override bool FinishedLaunching (UIApplication app, NSDictionary options) { var root = new RootElement ("Xamarin.Social Sample"); var section = new Section ("Services"); var facebookButton = new StringElement ("Share with Facebook"); facebookButton.Tapped += delegate { Share (Facebook, facebookButton); }; section.Add (facebookButton); var twitterButton = new StringElement ("Share with Twitter"); twitterButton.Tapped += delegate { Share (Twitter, twitterButton); }; section.Add (twitterButton); var twitter5Button = new StringElement ("Share with built-in Twitter"); twitter5Button.Tapped += delegate { Share (Twitter5, twitter5Button); }; section.Add (twitter5Button); var flickr = new StringElement ("Share with Flickr"); flickr.Tapped += () => { var picker = new MediaPicker(); // Set breakpoint here picker.PickPhotoAsync().ContinueWith (t => { if (t.IsCanceled) return; var item = new Item ("I'm sharing great things using Xamarin!") { Images = new[] { new ImageData (t.Result.Path) } }; Console.WriteLine ("Picked image {0}", t.Result.Path); UIViewController viewController = Flickr.GetShareUI (item, shareResult => { dialog.DismissViewController (true, null); flickr.GetActiveCell().TextLabel.Text = "Flickr shared: " + shareResult; }); dialog.PresentViewController (viewController, true, null); }, TaskScheduler.FromCurrentSynchronizationContext()); }; section.Add (flickr); root.Add (section); dialog = new DialogViewController (root); window = new UIWindow (UIScreen.MainScreen.Bounds); window.RootViewController = new UINavigationController (dialog); window.MakeKeyAndVisible (); return true; }
protected override void OnCreate (Bundle bundle) { base.OnCreate (bundle); SetContentView (Resource.Layout.Main); Button flickrButton = FindViewById<Button> (Resource.Id.Flickr); flickrButton.Click += (sender, args) => { var picker = new MediaPicker (this); picker.PickPhotoAsync().ContinueWith (t => { if (t.IsCanceled) return; var item = new Item ("I'm sharing great things using Xamarin!") { Images = new[] { new ImageData (t.Result.Path) } }; Intent intent = Flickr.GetShareUI (this, item, shareResult => { flickrButton.Text = "Flickr shared: " + shareResult; }); StartActivity (intent); }, TaskScheduler.FromCurrentSynchronizationContext()); }; Button facebookButton = FindViewById<Button>(Resource.Id.Facebook); facebookButton.Click += (sender, args) => Share (Facebook, facebookButton); Button twitterButton = FindViewById<Button> (Resource.Id.Twitter); twitterButton.Click += (sender, args) => Share (Twitter, twitterButton); }