private async void CaptureVideo() { ///data/user/0/com.companyname.mediapickerspike/files/ed3f5961-4554-4a3f-ba3d-dd44020745562062848124215052442.mp4 try { var video = await MediaPicker.CaptureVideoAsync(new MediaPickerOptions { Title = "Record Video" }); var stream = await video.OpenReadAsync(); var documentPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); var localPath = Path.Combine(documentPath, video.FileName); File.WriteAllBytes(localPath, stream.ReadAllBytes()); Videos.Add(new UserVideo { FullPath = localPath, VideoId = video.FileName, Name = $"Test Video {Videos.Count}" }); } catch (Exception e) { Console.WriteLine(e); } }
public void SnapPic() { var activity = Forms.Context as Activity; var picker = new MediaPicker(activity); if (!picker.IsCameraAvailable) { Console.WriteLine("No camera!"); } else { var intent = picker.GetTakePhotoUI(new StoreCameraMediaOptions { Name = "test.jpg", Directory = "MediaPickerSample" }); activity.StartActivityForResult(intent, 1); } // //var piker = new MediaPicker(activity); //var intent = piker.GetTakePhotoUI(new StoreCameraMediaOptions() //{ // Name = "test.jpg", // DefaultCamera = CameraDevice.Front, // Directory = "fotos" //}); //activity.StartActivityForResult(intent, 1); }
async void PresentCamera() { var picker = new MediaPicker(Context); if (!picker.IsCameraAvailable) { System.Console.WriteLine("No camera!"); } else { try { // TakePhotoAsync is deprecated? var file = await picker.TakePhotoAsync(new StoreCameraMediaOptions { Name = "test.jpg", Directory = "CouchbaseConnect", DefaultCamera = CameraDevice.Rear }); Console.WriteLine(file.Path); ((CameraContentPage)this.Element).Captured = file.Path; } catch (Exception e) { Console.WriteLine("Take Photo Cancelled."); } ((CameraContentPage)this.Element).IsPresented = false; } }
async void doCameraPhoto(PhotoListData pld) { #if __ANDROID__ MediaPicker picker = new MediaPicker(Forms.Context); #else MediaPicker picker = new MediaPicker(); #endif if (picker.IsCameraAvailable == false) { var page = new ContentPage(); var result = page.DisplayAlert("Warning", "Camera is not available", "OK"); return; } else { try { var resultfile = await picker.TakePhoto(null); #if __ANDROID__ showDrawingView(pld); #else showDrawingView(pld); #endif } catch (Exception ex) { } } }
public async void SnapPic() { var picker = new MediaPicker(); var mediafile = await picker.PickPhotoAsync(); System.Diagnostics.Debug.WriteLine(mediafile.Path); }
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); } }
public async Task <string> TakePhotoFullPathAsync() { string fullPath = ""; try { var photo = await MediaPicker.CapturePhotoAsync(new MediaPickerOptions { Title = $"xamarin.{DateTime.Now.ToString("dd.MM.yyyy_hh.mm.ss")}.png" }); var newFile = Path.Combine(FileSystem.AppDataDirectory, photo.FileName); using (var stream = await photo.OpenReadAsync()) { using (var newStream = File.OpenWrite(newFile)) { await stream.CopyToAsync(newStream); } } fullPath = photo.FullPath; } catch (Exception ex) { await UserDialogs.Instance.AlertAsync(ex.Message); } return(fullPath); }
public async void TakePictureFromCamera() { var picker = new MediaPicker(); if (!picker.IsCameraAvailable) { System.Diagnostics.Debug.WriteLine("No camera!"); } else { try { MediaFile file = await picker.TakePhotoAsync(new StoreCameraMediaOptions { Name = "imported.jpg", Directory = "tmp" }); MessagingCenter.Send <IPictureTaker, string>(this, "pictureTaken", file.Path); System.Diagnostics.Debug.WriteLine(file.Path); } catch (OperationCanceledException) { System.Diagnostics.Debug.WriteLine("Canceled"); } } }
/// <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; }); }); }
/// <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; }); }); }
/// <summary> /// Event handler when the user clicks the pick a video button /// </summary> /// <param name='sender'> /// Sender /// </param> partial void pickVideoBtnClicked(MonoTouch.Foundation.NSObject sender) { Console.WriteLine("pickVideoBtnClicked"); picker = new MediaPicker(); // Check that videos are supported on this device if (!picker.VideosSupported) { ShowUnsupported(); return; } // // Call PickideoAsync, which returns a Task<MediaFile> picker.PickVideoAsync() .ContinueWith(t => // Continue when the user has picked a video { if (t.IsCanceled) // The user canceled { return; } // Play the video the user picked InvokeOnMainThread(delegate { moviePlayer = new MPMoviePlayerViewController(NSUrl.FromFilename(t.Result.Path)); moviePlayer.MoviePlayer.UseApplicationAudioSession = true; this.PresentMoviePlayerViewController(moviePlayer); }); }); }
/// <summary> /// Event handler when the user clicks the Take a Video button /// </summary> /// <param name='sender'> /// Sender /// </param> partial void takeVideoBtnClicked(MonoTouch.Foundation.NSObject sender) { Console.WriteLine("takeVideoBtnClicked"); picker = new MediaPicker(); // Check if a camera is available and videos are supported on this device if (!picker.IsCameraAvailable || !picker.VideosSupported) { ShowUnsupported(); return; } // Call TakeVideoAsync, which returns a Task<MediaFile>. picker.TakeVideoAsync(new StoreVideoOptions { Quality = VideoQuality.Medium, DesiredLength = new TimeSpan(0, 0, 30) }) .ContinueWith(t => // Continue when the user has finished recording { if (t.IsCanceled) // The user canceled { return; } // Play the video the user recorded InvokeOnMainThread(delegate { moviePlayer = new MPMoviePlayerViewController(NSUrl.FromFilename(t.Result.Path)); moviePlayer.MoviePlayer.UseApplicationAudioSession = true; this.PresentMoviePlayerViewController(moviePlayer); }); }); }
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); } }
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); }); }
async partial void OnTakePhoto() { var picker = new MediaPicker(); if (!picker.IsCameraAvailable) { await DisplayAlert("Error", "No Camera Available!", "OK"); } else { try { MediaFile file = await picker.TakePhotoAsync(new StoreCameraMediaOptions { Name = "test.jpg", Directory = "photos", DefaultCamera = CameraDevice.Rear, }); Image image = new Image { Source = ImageSource.FromStream(file.GetStream) }; this.Content = image; } catch (OperationCanceledException ex) { Console.WriteLine("Operation canceled."); } } }
private async Task SendAttachmentsEmail(bool usePlatformApi = true) { var mediaPicker = new MediaPicker(); MediaFile mediaFile = await mediaPicker.PickPhotoAsync(); if (mediaFile != null) { IEmailMessage email; if (usePlatformApi) { NSUrl url = new NSUrl(mediaFile.Path, false); email = SamplesExtensions.BuildSampleEmail() .WithAttachment(url) .Build(); } else { // Hard coded mimetype for sample. Should query file to determine at run-time email = SamplesExtensions.BuildSampleEmail() .WithAttachment(mediaFile.Path, @"image/jpeg") .Build(); } CrossMessaging.Current.EmailMessenger.SendSampleEmail(email); } }
async void PickPhotoAsync() { try { var photo = await MediaPicker.PickPhotoAsync(); var stream = await photo.OpenReadAsync(); avatar.Source = ImageSource.FromStream(() => stream); var img = App.firebase.storage.Child("images").Child(App.firebase.currentUser.LocalId + ".png").PutAsync(await photo.OpenReadAsync()); img.Progress.ProgressChanged += (s, e) => Console.WriteLine($"Progress: {e.Percentage} %"); var img_url = await img; var res = await App.firebase.auth.UpdateProfileAsync(App.firebase.userLink.FirebaseToken, App.firebase.userLink.User.DisplayName, img_url); App.firebase.currentUser = res.User; var page = Application.Current.MainPage.Navigation.NavigationStack.Last() as SlideMenu.SlideMenu; page.refresh(); Console.WriteLine($"CapturePhotoAsync COMPLETED: {img_url}"); } catch (Exception ex) { Console.WriteLine($"CapturePhotoAsync THREW: {ex}"); } }
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); }); }
private async Task Scan() { var status = await Permissions.CheckStatusAsync <Permissions.Camera>(); if (status != PermissionStatus.Granted) { status = await Permissions.RequestAsync <Permissions.Camera>(); } if (status != PermissionStatus.Granted) { return; } try { var photo = await MediaPicker.CapturePhotoAsync(); using (var stream = await photo.OpenReadAsync()) { var scanResults = await _ocrService.ProcessImage(stream); _currentImageService.ScanResult = scanResults; await _navigationService.NavigateAsync(nameof(ScanPreviewPage)); } //await LoadPhotoAsync(photo); //Console.WriteLine($"CapturePhotoAsync COMPLETED: {PhotoPath}"); } catch (Exception ex) { Console.WriteLine($"CapturePhotoAsync THREW: {ex.Message}"); } }
public static async Task <Stream> ChoosePicture() { try { var picker = new MediaPicker(); await picker.PickPhotoAsync().ContinueWith(t => { PhotoMediaFile = t.Result; Console.WriteLine(PhotoMediaFile.Path); }, TaskScheduler.FromCurrentSynchronizationContext()); var photoStream = PhotoMediaFile.GetStream(); if (photoStream != null) { return(photoStream); } else { await UserDialogs.Instance.AlertAsync("No photos library accessible", "Photos Library missing", "OK"); } } catch (Exception e) { Console.WriteLine("PhotoPickerService.ChoosePicture() error: {0} - {1}", e.Message, e.StackTrace); } return(null); }
async void OpenImagePicker() { //It works? Don't use gallery var robotImagePicker = new MediaPicker(Forms.Context); await robotImagePicker.TakePhotoAsync(new StoreCameraMediaOptions { Name = data["teamNumber"].ToString() + ".jpg", Directory = "Robot Images" }).ContinueWith(t => { robotImageFile = t.Result; Console.WriteLine("Robot Image Path: " + robotImageFile.Path); }, TaskScheduler.FromCurrentSynchronizationContext()); robotImage.Source = robotImageFile.Path; try{ ParseFile image = new ParseFile(data["teamNumber"].ToString() + ".jpg", ImageToBinary(robotImageFile.Path)); data["robotImage"] = image; await data.SaveAsync(); popUpReturn(); } catch { Console.WriteLine("Image Save Error"); } }
async void OnScanBarcodeFromImage(System.Object sender, System.EventArgs e) { var result = await MediaPicker.PickPhotoAsync(); if (result != null) { var stream = await result.OpenReadAsync(); var bytes = new byte[stream.Length]; await stream.ReadAsync(bytes, 0, bytes.Length); stream.Seek(0, SeekOrigin.Begin); List <GoogleVisionBarCodeScanner.BarcodeResult> obj = await GoogleVisionBarCodeScanner.Methods.ScanFromImage(bytes); string ss = string.Empty; for (int i = 0; i < obj.Count; i++) { ss += $"{i + 1}. BarcodeType : {obj[i].BarcodeType}, Barcode : {obj[i].DisplayValue}{Environment.NewLine}"; } Device.BeginInvokeOnMainThread(async() => { LblBarcodeValue.Text = ss; await DisplayAlert("Selected Barcode Detail", ss, "ok"); }); } }
private async void Button_Clicked_1(object sender, EventArgs e) { var result = await MediaPicker.CapturePhotoAsync(); if (result != null) { var stream = await result.OpenReadAsync(); resultImage.Source = ImageSource.FromStream(() => stream); } //try //{ // var photo = await MediaPicker.CapturePhotoAsync(); // await LoadPhotoAsync(photo); // Console.WriteLine($"CapturePhotoAsync COMPLETED: {PhotoPath}"); //} //catch (FeatureNotSupportedException fnsEx) //{ // Console.WriteLine($"CapturePhotoAsync THREW: {fnsEx.Message}"); //} //catch (PermissionException pEx) //{ // Console.WriteLine($"CapturePhotoAsync THREW: {pEx.Message}"); //} //catch (Exception ex) //{ // Console.WriteLine($"CapturePhotoAsync THREW: {ex.Message}"); //} }
async void doPhotoLibrary(PhotoListData pld) { #if __ANDROID__ MediaPicker picker = new MediaPicker(Forms.Context); #else MediaPicker picker = new MediaPicker(); #endif if (picker.IsPhotoGalleryAvailable == false) { var page = new ContentPage(); var result = page.DisplayAlert("Warning", "Photo is not available", "OK"); return; } else { try { var resultfile = await picker.PickPhoto(); #if __ANDROID__ //showDrawingView(pld); #else //showDrawingView(pld); #endif } catch (Exception e) { } } }
private void ButtonSendAttachmentEmail_Click(object sender, EventArgs eventArgs) { var picker = new MediaPicker(Application.Context); var intent = picker.GetPickPhotoUI(); StartActivityForResult(intent, SelectPhoto); }
async private void TapGestureRecognizer_Tapped(object sender, EventArgs e) { string answer = await DisplayActionSheet("Đổi ảnh đại diện bằng ?", "Hủy", null, "Camera", "Chọn ảnh"); if (answer == "Chọn ảnh") { var result = await MediaPicker.PickPhotoAsync(new MediaPickerOptions { Title = "Please pick a photo" }); if (result != null) { var stream = await result.OpenReadAsync(); resultImage.Source = ImageSource.FromStream(() => stream); } } else if (answer == "Camera") { var result = await MediaPicker.CapturePhotoAsync(new MediaPickerOptions { Title = "Please pick a photo" }); if (result != null) { var stream = await result.OpenReadAsync(); resultImage.Source = ImageSource.FromStream(() => stream); } } }
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()); } }; }
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 void GetPhotoFromCamera() { var context = MainApplication.CurrentContext as Activity; if (context == null) { return; } var picker = new MediaPicker(context); if (picker.IsCameraAvailable) { try { var intent = picker.GetTakePhotoUI(new StoreCameraMediaOptions { Name = "photo.jpg", Directory = "ContatosPickerPhoto", DefaultCamera = CameraDevice.Front }); if (IsIntentAvailable(context, intent)) { context.StartActivityForResult(intent, PhotoConstant.REQUEST_CAMERA); } } catch (OperationCanceledException) { } } }
public static async Task <FileInfo> TakePhotoAsync() { try { var photo = await MediaPicker.CapturePhotoAsync(); var file = await LoadPhotoAsync(photo); Console.WriteLine($"CapturePhotoAsync COMPLETED: {file}"); return(file); } catch (FeatureNotSupportedException) { // Feature is now supported on the device } catch (PermissionException) { // Permissions not granted } catch (Exception ex) { Console.WriteLine($"CapturePhotoAsync THREW: {ex.Message}"); } return(null); }
void MediaChooser (object sender, UIButtonEventArgs e) { if (e.ButtonIndex == 1) { System.Console.WriteLine ("Camera"); var picker = new MediaPicker (); // new MediaPicker (this); on Android 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() ); } image_bytes = UIImageViewToByteArray(imageView.Image); image.Dispose (); } 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()); } //MOKEEEEEEEEE UIImage To ByteArray image = imageView.Image; image_bytes = UIImageViewToByteArray(image); image.Dispose (); }