示例#1
0
        private async void cameraToolbarItem_Clicked(object sender, EventArgs e)
        {
            if (CrossMedia.Current.IsTakePhotoSupported)
            {
                var mediaOptions = new Plugin.Media.Abstractions.StoreCameraMediaOptions
                {
                    Directory = "SkinMarks",
                    Name      = $"{DateTime.UtcNow}.jpg"
                };

                var file = await CrossMedia.Current.TakePhotoAsync(mediaOptions);

                if (file == null)
                {
                    await DisplayAlert("Error", "Ocurrió un error al obtener la imagen", "Ok");

                    return;
                }

                var stream = file.GetStream();
                photoImage.Source = ImageSource.FromStream(() => stream);

                await MakePredictionAsync(stream);
            }
        }
示例#2
0
        private async void emotion_Clicked(object sender, EventArgs e)
        {
            var emotionClient = new EmotionServiceClient("ccd94bca7ccc4e0d9b45b200088990e9");
            await CrossMedia.Current.Initialize();

            if (CrossMedia.Current.IsCameraAvailable && CrossMedia.Current.IsTakePhotoSupported)
            {
                // Supply media options for saving our photo after it's taken.
                var mediaOptions = new Plugin.Media.Abstractions.StoreCameraMediaOptions
                {
                    Directory = "Receipts",
                    Name      = $"{DateTime.UtcNow}.jpg"
                };

                // Take a photo of the business receipt.
                var file = await CrossMedia.Current.TakePhotoAsync(mediaOptions);

                using (var photoStream = file.GetStream())
                {
                    Emotion[] emotionResult = await emotionClient.RecognizeAsync(photoStream);

                    if (emotionResult.Any())
                    {
                        // Emotions detected are happiness, sadness, surprise, anger, fear, contempt, disgust, or neutral.
                        lblrating.Text = emotionResult.FirstOrDefault().Scores.ToRankedList().FirstOrDefault().Key;
                    }
                    file.Dispose();
                }
            }

            //var visionclient = new VisionServiceClient(visionKey);
            //var result = await visionclient.DescribeAsync(file.GetStream());
            //LblResult.Text = result.Description.Captions.First().Text;
        }
示例#3
0
        // public static IPhotoPicker PhotoPicker { get; set; }
        public static async Task <MediaFile> GetPhoto(Page pg)
        {
            if (!CrossMedia.IsSupported)
            {
                return(null);
            }
            var at = await pg.DisplayActionSheet("Выберите источник изображения", "Отмена", null, "Галерея", "Камера");

            if (at == "Камера" || at == "Галерея")
            {
                await CrossMedia.Current.Initialize();

                if (CrossMedia.Current.IsCameraAvailable && CrossMedia.Current.IsTakePhotoSupported)
                {
                    // Supply media options for saving our photo after it's taken.
                    var mediaOptions = new Plugin.Media.Abstractions.StoreCameraMediaOptions
                    {
                        Directory = "Receipts",
                        Name      = $"{DateTime.UtcNow}.jpg"
                    };

                    // Take a photo of the business receipt.

                    // var file = await CrossMedia.Current.TakePhotoAsync(mediaOptions);
                    var f = await CrossMedia.Current.TakePhotoAsync(mediaOptions);

                    // callback?.Invoke(f);
                    return(f);
                }
            }

            return(null);
        }
示例#4
0
        private async void Button_Clicked(Object sender, EventArgs args)
        {
            await CrossMedia.Current.Initialize();

            if (CrossMedia.Current.IsCameraAvailable && CrossMedia.Current.IsTakePhotoSupported)
            {
                // Supply media options for saving our photo after it's taken.
                var mediaOptions = new Plugin.Media.Abstractions.StoreCameraMediaOptions
                {
                    Directory = "Clientes",
                    Name      = $"{DateTime.UtcNow}.jpg"
                };

                // Take a photo of the business receipt.
                var file = await CrossMedia.Current.TakePhotoAsync(mediaOptions);

                Save(file.GetStream());

                /*
                 * imgFoto.Source = ImageSource.FromStream(() =>
                 * {
                 *  var stream = file.GetStream();
                 *  return stream;
                 * });
                 */
            }
        }
示例#5
0
        private async void TakeButtonClicked(object sender, EventArgs e)
        {
            await CrossMedia.Current.Initialize();

            if (CrossMedia.Current.IsCameraAvailable && CrossMedia.Current.IsTakePhotoSupported)
            {
                var MediaOptions = new Plugin.Media.Abstractions.StoreCameraMediaOptions
                {
                    Directory = "Receipts",
                    Name      = $"{DateTime.UtcNow}.jpg"
                };

                MediaFile file = await CrossMedia.Current.TakePhotoAsync(MediaOptions);

                if (file == null)
                {
                    return;
                }

                foodImage.Source = ImageSource.FromStream(() =>
                {
                    return(file.GetStream());
                });

                foodLabel.Text        = "";
                shareButton.IsVisible = false;
                await MakePredictionRequest(file);
            }
        }
示例#6
0
        public static async Task <MediaFile> TakePhoto()
        {
            await CrossMedia.Current.Initialize();

            if (CrossMedia.Current.IsCameraAvailable && CrossMedia.Current.IsTakePhotoSupported)
            {
                // Supply media options for saving our photo after it's taken.
                var mediaOptions = new Plugin.Media.Abstractions.StoreCameraMediaOptions
                {
                    Directory     = "Receipts",
                    Name          = $"{DateTime.UtcNow}.jpg",
                    DefaultCamera = Plugin.Media.Abstractions.CameraDevice.Rear,
                    //PhotoSize = PhotoSize.Small
                };

                // Take a photo of the business receipt.
                MediaFile file = await CrossMedia.Current.TakePhotoAsync(mediaOptions);

                return(file);
            }
            else
            {
                return(null);
            }
        }
        internal MediaPickerDelegate(UIViewController viewController, UIImagePickerControllerSourceType sourceType, StoreCameraMediaOptions options)
        {
            this.viewController = viewController;
            this.source = sourceType;
            this.options = options ?? new StoreCameraMediaOptions();

            if (viewController != null)
            {
                UIDevice.CurrentDevice.BeginGeneratingDeviceOrientationNotifications();
                observer = NSNotificationCenter.DefaultCenter.AddObserver(UIDevice.OrientationDidChangeNotification, DidRotate);
            }
        }
示例#8
0
        async void TakePhoto(object sender, EventArgs eventArgs)
        {
            await CrossMedia.Current.Initialize();

            if (!await GetCameraPermission())
            {
                return;
            }

            if (!CrossMedia.Current.IsCameraAvailable ||
                !CrossMedia.Current.IsTakePhotoSupported)
            {
                await DisplayAlert("No Camera", "No camera available", "Not cool...");

                return;
            }

            var frontOrBackCamera = cameraSwitch.IsToggled ?
                                    Plugin.Media.Abstractions.CameraDevice.Rear :
                                    Plugin.Media.Abstractions.CameraDevice.Front;

            var imgStoreOptions = new Plugin.Media.Abstractions.StoreCameraMediaOptions()
            {
                Directory     = "Pictures",
                Name          = "test.jpg",
                DefaultCamera = frontOrBackCamera
            };

            MediaFile capturedPhoto;

            try
            {
                capturedPhoto = await CrossMedia.Current.TakePhotoAsync(imgStoreOptions);
            }
            catch (Exception)
            {
                await DisplayAlert("Failed operation", "Couldn't take a photo.", "Ok");

                return;
            }

            if (capturedPhoto == null)
            {
                return;
            }

            var preView = new CameraCapturePreview();

            preView.SetPreviewImg(capturedPhoto);

            await Navigation.PushAsync(preView);
        }
示例#9
0
        private async Task ExecuteTakePhotoCommandAsync()
        {
            IsBusy = true;
            if (CrossMedia.Current.IsCameraAvailable && CrossMedia.Current.IsTakePhotoSupported)
            {
                // Supply media options for saving our photo after it's taken.
                var mediaOptions = new Plugin.Media.Abstractions.StoreCameraMediaOptions
                {
                    Directory = "CognitiveTest",
                    Name      = $"{DateTime.UtcNow}.jpg"
                };

                var file = await CrossMedia.Current.TakePhotoAsync(mediaOptions);

                if (file != null)
                {
                    imageFileSource = file.Path;
                    var faces = await UploadAndDetectFaces(file);

                    if (faces != null)
                    {
                        IsBusy = false;
                        var faceList = new List <FaceView>();
                        var index    = 1;
                        foreach (var face in faces)
                        {
                            if (face.FaceAttributes != null)
                            {
                                faceList.Add(new FaceView(index, face.FaceAttributes));
                            }
                            index++;
                        }

                        Faces.ReplaceRange(faceList);
                    }
                    else
                    {
                        MessagingService.Current.SendMessage <MessagingServiceAlert>(MessagingKeys.CognitiveServiceErrorMessage,
                                                                                     new MessagingServiceAlert()
                        {
                            Cancel  = "Cancel",
                            Message = "Could not get " +
                                      "data, please check your network",
                            Title = "Error"
                        });
                    }
                }
            }
        }
示例#10
0
        private async void TakePhoneBtn_Clicked(object sender, EventArgs e)
        {
            Plugin.Media.Abstractions.StoreCameraMediaOptions options = new Plugin.Media.Abstractions.StoreCameraMediaOptions()
            {
                SaveToAlbum   = false,
                DefaultCamera = CameraDevice.Front,
            };
            mediaFile = await CrossMedia.Current.TakePhotoAsync(options);

            CameraImage.Source = ImageSource.FromStream(() =>
            {
                return(mediaFile.GetStream());
            });
            _imageStream = mediaFile.GetStream();
        }
示例#11
0
        private async void TirarFoto(object sender, EventArgs e)
        {
            if (CrossMedia.Current.IsCameraAvailable && CrossMedia.Current.IsTakePhotoSupported)
            {
                var mediaOptions = new Plugin.Media.Abstractions.StoreCameraMediaOptions
                {
                    SaveToAlbum = true,
                    Directory   = $"{DateTime.UtcNow}.jpg"
                };


                // Take a photo of the business receipt.
                var file = await CrossMedia.Current.TakePhotoAsync(mediaOptions);
            }
        }
示例#12
0
        private async Task ExecuteTakePhotoCommandAsync()
        {
            IsBusy = true;
            if (CrossMedia.Current.IsCameraAvailable && CrossMedia.Current.IsTakePhotoSupported)
            {
                // Supply media options for saving our photo after it's taken.
                var mediaOptions = new Plugin.Media.Abstractions.StoreCameraMediaOptions
                {
                    Directory = "CognitiveTest",
                    Name      = $"{DateTime.UtcNow}.jpg"
                };

                var file = await CrossMedia.Current.TakePhotoAsync(mediaOptions);

                if (file != null)
                {
                    imageFileSource = ImageSource.FromStream(file.GetStream);
                    var emotionResult = await UploadAndDetectEmotions(file);

                    if (emotionResult != null)
                    {
                        var scoreList  = new List <ScoresView>();
                        var faceNumber = 1;
                        foreach (var emotion in emotionResult)
                        {
                            scoreList.Add(new ScoresView(faceNumber, emotion.Scores));
                            faceNumber++;
                        }

                        Scores.ReplaceRange(scoreList);
                        IsBusy = false;
                    }
                    else
                    {
                        MessagingService.Current.SendMessage <MessagingServiceAlert>(MessagingKeys.CognitiveServiceErrorMessage,
                                                                                     new MessagingServiceAlert()
                        {
                            Cancel  = "Cancel",
                            Message = "Could not get " +
                                      "data, please check your network",
                            Title = "Error"
                        });
                    }
                }
            }
        }
示例#13
0
        public async void DoFromCamera()
        {
            try
            {
                if (!CrossMedia.Current.IsCameraAvailable || !CrossMedia.Current.IsTakePhotoSupported)
                {
                    return;
                }

                var status = await CrossPermissions.Current.CheckPermissionStatusAsync(Permission.Camera);

                if (status != PermissionStatus.Granted)
                {
                    if (await CrossPermissions.Current.ShouldShowRequestPermissionRationaleAsync(Permission.Camera))
                    {
                        var results = await CrossPermissions.Current.RequestPermissionsAsync(new[] { Permission.Camera });

                        status = results[Permission.Camera];
                    }
                }

                if (status == PermissionStatus.Granted)
                {
                    var mediaOptions = new Plugin.Media.Abstractions.StoreCameraMediaOptions
                    {
                        SaveToAlbum = false
                    };
                    var file = await CrossMedia.Current.TakePhotoAsync(mediaOptions);

                    if (file == null)
                    {
                        return;
                    }
                    SelectedFile = file;
                }
                else if (status != PermissionStatus.Unknown)
                {
                    NavigationHandler.GlobalNavigator.DisplayAlert(Constants.APP_NAME, Constants.PERMISSION_DENIED, Constants.OK_TEXT);
                }
            }
            catch (Exception ex)
            {
                NavigationHandler.GlobalNavigator.DisplayAlert(Constants.APP_NAME, Constants.CAMERA_FAIL, Constants.OK_TEXT);
            }
        }
示例#14
0
        async void TakePictureButton_Clicked(object sender, EventArgs e)
        {
            await CrossMedia.Current.Initialize();

            if (!CrossMedia.Current.IsCameraAvailable || !CrossMedia.Current.IsTakePhotoSupported)
            {
                throw new Exception("No camera available.");
            }


            var opts = new Plugin.Media.Abstractions.StoreCameraMediaOptions
            {
                //PhotoSize = PhotoSize.Full,
                //SaveToAlbum = true,
                //CompressionQuality = 90,
                //SaveMetaData = false,
                AllowCropping = true,
            };

            var file = await CrossMedia.Current.TakePhotoAsync(opts);



            var photo = file?.GetStream();

            if (photo != null)
            {
                var tessResult = await _tesseractApi.SetImage(photo);

                if (tessResult)
                {
                    var textReconized = _tesseractApi.Text;
                    var resultado     = textReconized.Contains("Importe venta");
                    var test          = _tesseractApi.Results(PageIteratorLevel.Textline);
                    foreach (var item in test)
                    {
                        if (item.Text.Contains("IMPORTE VENTA"))
                        {
                            MyStringProperty = item.Text;
                        }
                    }
                }
            }
        }
示例#15
0
        public async Task <byte[]> SendPicture(bool camera)
        {
            if (CrossMedia.Current.IsCameraAvailable && CrossMedia.Current.IsTakePhotoSupported)
            {
                //Supply media options for saving our photo after it's taken.
                var pictureMediaOptions = new Plugin.Media.Abstractions.StoreCameraMediaOptions
                {
                    Directory = "Receipts",
                    Name      = $"{DateTime.UtcNow}.jpg",
                    PhotoSize = PhotoSize.Small
                };

                var galleryMediaOptions = new Plugin.Media.Abstractions.PickMediaOptions
                {
                    PhotoSize = PhotoSize.Small
                };

                // Take a photo of the business receipt.
                MediaFile file;
                if (camera)
                {
                    file = await CrossMedia.Current.TakePhotoAsync(pictureMediaOptions);
                }
                else
                {
                    file = await CrossMedia.Current.PickPhotoAsync(galleryMediaOptions);
                }

                if (file != null)
                {
                    var stream = file.GetStream();
                    file.Dispose();
                    byte[] imageData = GetImageStreamAsBytes(stream);
                    return(imageData);
                }

                return(null);
            }

            return(null);
        }
示例#16
0
        private async Task ExecuteTakePhotoCommandAsync()
        {
            IsBusy = true;
            if (CrossMedia.Current.IsCameraAvailable && CrossMedia.Current.IsTakePhotoSupported)
            {
                // Supply media options for saving our photo after it's taken.
                var mediaOptions = new Plugin.Media.Abstractions.StoreCameraMediaOptions
                {
                    Directory = "CognitiveTest",
                    Name      = $"{DateTime.UtcNow}.jpg"
                };

                var file = await CrossMedia.Current.TakePhotoAsync(mediaOptions);

                if (file != null)
                {
                    tempFileWorking = file;
                    CallDisplaySheetOnView();
                }
            }
        }
示例#17
0
        public async Task <MediaFile> PrendrePhoto()
        {
            try
            {
                await CrossMedia.Current.Initialize();

                if (CrossMedia.Current.IsCameraAvailable && CrossMedia.Current.IsTakePhotoSupported)
                {
                    var media = new Plugin.Media.Abstractions.StoreCameraMediaOptions
                    {
                        Directory = "Sample",
                        Name      = $"{DateTime.UtcNow}.jpg"
                    };

                    var file = await CrossMedia.Current.TakePhotoAsync(media);

                    return(file);
                }
            }
            catch (Exception e) { Console.WriteLine(e); }
            return(null);
        }
        private async void BtnTakePhoto_Clicked(object sender, EventArgs e)
        {
            if (CrossMedia.Current.IsCameraAvailable && CrossMedia.Current.IsTakePhotoSupported)
            {
                // Supply media options for saving our photo after it's taken.
                var mediaOptions = new Plugin.Media.Abstractions.StoreCameraMediaOptions
                {
                    Directory          = "MediaPlugin",
                    Name               = DateTime.Now + ".jpg",
                    DefaultCamera      = Plugin.Media.Abstractions.CameraDevice.Front,
                    SaveToAlbum        = false,
                    CompressionQuality = 40,
                    PhotoSize          = Plugin.Media.Abstractions.PhotoSize.Small
                };
                //mainFile = mediaOptions;


                // Take a photo of the business receipt.
                var file = await CrossMedia.Current.TakePhotoAsync(mediaOptions);

                mainFile = file;
                if (file == null)
                {
                    return;
                }
                imgProfilePicture.Source = ImageSource.FromStream(() =>
                {
                    var stream = file.GetStream();
                    //imgStream = stream;
                    //file.Dispose();

                    return(stream);
                });
                btnConfirm.IsEnabled       = true;
                btnConfirm.BackgroundColor = Color.FromHex("#71d18b");
            }
        }
示例#19
0
        private async void CameraOption2(object sender, EventArgs e)
        {
            try
            {
                if (!CrossMedia.Current.IsCameraAvailable || !CrossMedia.Current.IsTakePhotoSupported)
                {
                    await DisplayAlert("No Camera", ":( No camera avaialble.", "OK");
                    return;
                }
                var mediaOptions = new Plugin.Media.Abstractions.StoreCameraMediaOptions
                {
                    Directory = "ShopRConnect",
                    Name = $"{DateTime.UtcNow}.jpg"
                };

                file = await CrossMedia.Current.TakePhotoAsync(new StoreCameraMediaOptions
                {
                    CompressionQuality = 10,
                    PhotoSize = PhotoSize.Small
                });
                FilePath = file.Path;
                FileName = FilePath.Substring(FilePath.LastIndexOf("/") + 1);

                var content = new MultipartFormDataContent();




            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex);
                await DisplayAlert("Alert", "Please check your Internet connection", "Ok");
                Actimageupload.IsRunning = false;
                //   await Navigation.PopPopupAsync();
            }
        }
示例#20
0
        private async void UploadImageViaCamera()
        {
            await CrossMedia.Current.Initialize();

            var mediaOptions = new Plugin.Media.Abstractions.StoreCameraMediaOptions
            {
                Directory          = "LeftBehind",
                PhotoSize          = PhotoSize.Full,
                CompressionQuality = 50,
                AllowCropping      = true,
                Name = "Camera.jpg",
            };

            var file = await CrossMedia.Current.TakePhotoAsync(mediaOptions);

            if (file != null)
            {
                byte[] imageArray = System.IO.File.ReadAllBytes(file.Path);// convert path to byte array
                _imageSource = Convert.ToBase64String(imageArray);

                // Show image on UI
                switch (Device.RuntimePlatform)
                {
                case Device.iOS:
                    image.Source = ImageSource.FromFile(file.Path);
                    break;

                case Device.Android:
                    image.Source = ImageSource.FromStream(() =>
                    {
                        var stream = file.GetStream();
                        return(stream);
                    });
                    break;
                }
            }
        }
示例#21
0
        private async Task InitiateCamera()
        {
            if (CrossMedia.Current.IsCameraAvailable && CrossMedia.Current.IsTakePhotoSupported)
            {
                var mediaOptions = new Plugin.Media.Abstractions.StoreCameraMediaOptions
                {
                    Directory = "Photos",
                    Name      = $"{DateTime.UtcNow}.jpg",
                    PhotoSize = PhotoSize.Medium
                };
                Media = await CrossMedia.Current.TakePhotoAsync(mediaOptions);

                ImageTaken = ImageSource.FromStream(() => { return(Media.GetStream()); });

                try
                {
                    var result = await GetImageDescription(Media.GetStream());

                    if (result != null)
                    {
                        foreach (var caption in result.Description.Captions)
                        {
                            DescriptionText = caption.Text;
                        }
                    }
                }
                catch (Exception e)
                {
                    DescriptionText = e.Message;
                }
            }
            else
            {
                DescriptionText = "taking a photo is not available on your device";
            }
        }
示例#22
0
        private async void TakePhoto_Click(object sender, EventArgs e)
        {
            try
            {


                await CrossMedia.Current.Initialize();
                if (!CrossMedia.Current.IsCameraAvailable || !CrossMedia.Current.IsTakePhotoSupported) return;

                // Supply media options for saving our photo after it's taken.
                var mediaOptions = new StoreCameraMediaOptions
                {
                    Directory = "Media",
                    Name = $"{DateTime.Now:T}.jpg".Replace(":", "-"),
                    DefaultCamera = CameraDevice.Front,
                    SaveToAlbum = false
                };

                // Take a photo of the business receipt.
                var file = await CrossMedia.Current.TakePhotoAsync(mediaOptions);

                CurrentViewModel.ImageUrl = file.Path;
                //Image.Source = CurrentViewModel.ImageUrl;


                //await CurrentViewModel.VisionFaceCheckAsync(file);
                //await CurrentViewModel.VisionEmotionAsync(file);
                await CurrentViewModel.VisionComputerVisionAsync(file);
                var faceMetaData = CurrentViewModel.Xywh;




                //TestImage.Source = CurrentViewModel.ImageUrl;



                var face = new List<Rectangle>();
                var rectangle = new Rectangle();
                foreach (var s in faceMetaData)
                    if (s != null)
                    {
                        var xywh = s.Split(',');

                        rectangle.X = double.Parse(xywh[0]);
                        rectangle.Y = double.Parse(xywh[1]);
                        rectangle.Width = double.Parse(xywh[2]);
                        rectangle.Height = double.Parse(xywh[3]);

                        face.Add(rectangle);


                        //ResultLayout.Children.Add(frane, Constraint.RelativeToView(TestImage, (ResultLayout, TestImage) => left/imageWidht*this.TestImage.Width), Constraint.RelativeToView(TestImage, (ResultLayout, TestImage) => top/imageHeight*this.TestImage.Height), Constraint.RelativeToView(TestImage, (ResultLayout, TestImage) => width/imageWidht* this.TestImage.Width), Constraint.RelativeToView(TestImage, (ResultLayout, TestImage) => height/imageHeight * this.TestImage.Height));

                    }
                var imageMetadata = CurrentViewModel.ImageMetadata.Split(',');
                var imageWidth = int.Parse(imageMetadata[0]);
                var imageHeight = int.Parse(imageMetadata[1]);
                Debug.WriteLine($"current metadata\n{CurrentViewModel.ImageMetadata}");


                // Do some stuff to make sure the boxes render correctly
                using (var streamPic = file.GetStream())
                {
                    var picInfo = ExifReader.ReadJpeg(streamPic);
                    var orientation = picInfo.Orientation;
                    if ((orientation == ExifOrientation.BottomLeft || orientation == ExifOrientation.TopRight)
                        && imageHeight < imageWidth) // Orientation is wrong?
                    {
                        var temp = imageHeight;
                        imageHeight = imageWidth;
                        imageWidth = temp;
                    }
                }

                Layout.DrawRectangle(face, CurrentViewModel.ImageUrl, imageWidth, imageHeight);

                //string[] xywh = faceMetaData.Split(',');
                CurrentViewModel.WarningText = "Here is the computer vision results for you";
                //RectImage.Source = CurrentViewModel.ImageUrl;


                //CurrentViewModel.ImageUrl = file.Path;
                //await PclStorageSamle(file.Path);
            }
            catch (Exception ex)
            {
                // ignored
            }
        }
        /// <summary>
        /// Take a photo async with specified options
        /// </summary>
        /// <param name="options">Camera Media Options</param>
        /// <returns>Media file of photo or null if canceled</returns>
        public async Task<MediaFile> TakePhotoAsync(StoreCameraMediaOptions options)
        {
            if (!IsCameraAvailable)
                throw new NotSupportedException();

            if (!(await RequestCameraPermission().ConfigureAwait(false)))
            {
                return null;
            }


            VerifyOptions(options);

            return await TakeMediaAsync("image/*", MediaStore.ActionImageCapture, options);
        }
        /// <summary>
        /// Takes the photo.
        /// </summary>
        public async void TakePhoto()
        {
            /**
             * Step 1 : Check if Camera is available in mobile phone
             * Step 2 :Give a name to photo taken FileNumber + Barecode + timestamp . also remove any space and slash in photo name
             * Step 3 :Take Photo And save Image in given Directory and its path in database
             * Step 4 :Get Path from Db of corresponding File Number and Barecode to display them in carousel view
             */
            string barcodeNum = "", tempName = "";
            string bindingName = "";

            if (CrossMedia.Current.IsCameraAvailable && CrossMedia.Current.IsTakePhotoSupported)
            {
                if (_barcode != null && _fileNum != null)
                {
                    barcodeNum = _barcode;
                    var fileNum = _fileNum;
                    bindingName = fileNum + barcodeNum;


                    tempName = bindingName + $"{DateTime.UtcNow}.jpg".Replace(" ", "_");
                    System.Diagnostics.Debug.WriteLine(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> File + Barocde :" + bindingName);

                    if (tempName.Contains("/"))
                    {
                        tempName = tempName.Replace("/", "_");
                    }
                }
                // Supply media options for saving our photo after it's taken.
                var mediaOptions = new Plugin.Media.Abstractions.StoreCameraMediaOptions
                {
                    Directory          = "PhotoDirectory",
                    Name               = tempName,
                    PhotoSize          = PhotoSize.Small,
                    CompressionQuality = _qualityVal
                };
                // Take a photo of the business receipt.

                try
                {
                    var file = await CrossMedia.Current.TakePhotoAsync(mediaOptions);

                    if (file != null)
                    {
                        _photoPathList.Add(file.Path);
                        string photoPathLongString = String.Join(",", _photoPathList);

                        if (_status.Equals("delivery"))
                        {
                            SetActivityIndicator(true);
                            _delivery.PhotoPath         = photoPathLongString;
                            _delivery.comments_Delivery = PhotoComment;
                            _delivery.sent_delivery     = "False";
                            _delivery.Osds = Constants.Delivery;
                            System.Diagnostics.Debug.WriteLine(file.Path + " >>path of picture taken");
                            SaveDelivery();
                            await Task.Delay(TimeSpan.FromSeconds(4));

                            GetPhotoPathFromDb(_status, _barcode);
                        }
                        else
                        {
                            _loading.FileItemModel.PhotoPath        = photoPathLongString;
                            _loading.FileItemModel.Sent_Loading     = false;
                            _loading.FileItemModel.Comments_loading = PhotoComment;

                            System.Diagnostics.Debug.WriteLine(file.Path + " LOADING >>>>path of picture taken");
                            SaveLoading();
                            SetActivityIndicator(true);
                            await Task.Delay(TimeSpan.FromSeconds(5));

                            GetPhotoPathFromDb(_status, _barcode);
                            await UpdateLoadingPhotoTable(_loading.FileItemModel.PhotoPath, _loading);
                        }
                    }
                    else
                    {
                        System.Diagnostics.Debug.WriteLine("No picture was taken<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>");
                        return;
                    }
                }
                catch (Exception e)
                {
                    System.Diagnostics.Debug.WriteLine("catch" + e);
                }
            }
        }
        private Task<MediaFile> GetMediaAsync(UIImagePickerControllerSourceType sourceType, string mediaType, StoreCameraMediaOptions options = null)
        {
            UIWindow window = UIApplication.SharedApplication.KeyWindow;
            if (window == null)
                throw new InvalidOperationException("There's no current active window");

            UIViewController viewController = window.RootViewController;

            if (viewController == null)
            {
                window = UIApplication.SharedApplication.Windows.OrderByDescending(w => w.WindowLevel).FirstOrDefault(w => w.RootViewController != null);
                if (window == null)
                    throw new InvalidOperationException("Could not find current view controller");
                else
                    viewController = window.RootViewController;
            }

            while (viewController.PresentedViewController != null)
                viewController = viewController.PresentedViewController;

            MediaPickerDelegate ndelegate = new MediaPickerDelegate(viewController, sourceType, options);
            var od = Interlocked.CompareExchange(ref pickerDelegate, ndelegate, null);
            if (od != null)
                throw new InvalidOperationException("Only one operation can be active at at time");

            var picker = SetupController(ndelegate, sourceType, mediaType, options);

            if (UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad && sourceType == UIImagePickerControllerSourceType.PhotoLibrary)
            {
                ndelegate.Popover = new UIPopoverController(picker);
                ndelegate.Popover.Delegate = new MediaPickerPopoverDelegate(ndelegate, picker);
                ndelegate.DisplayPopover();
            }
            else
                viewController.PresentViewController(picker, true, null);

            return ndelegate.Task.ContinueWith(t =>
            {
                if (popover != null)
                {
                    popover.Dispose();
                    popover = null;
                }

                Interlocked.Exchange(ref pickerDelegate, null);
                return t;
            }).Unwrap();
        }
        /// <summary>
        /// This method takes a picture. 
        /// Right now the parameter is not evaluated.
        /// </summary>
        /// <param name="mode"></param>
        /// <param name="options"></param>
        /// <returns></returns>
        public async Task<StorageFile> CaptureFileAsync(CameraCaptureUIMode mode, StoreCameraMediaOptions options)
        {
            var t = IsStopped();
            options = options;
            // Create new MediaCapture 
            MyMediaCapture = new MediaCapture();
            var videoDevices = await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture);
            var backCamera = videoDevices.FirstOrDefault(
                item => item.EnclosureLocation != null
                && item.EnclosureLocation.Panel == Windows.Devices.Enumeration.Panel.Back);

            var frontCamera = videoDevices.FirstOrDefault(
                  item => item.EnclosureLocation != null
                  && item.EnclosureLocation.Panel == Windows.Devices.Enumeration.Panel.Front);

            var captureSettings = new MediaCaptureInitializationSettings();
            if(options.DefaultCamera == CameraDevice.Front && frontCamera != null)
            {
              captureSettings.VideoDeviceId = frontCamera.Id;
            }
            else if(options.DefaultCamera == CameraDevice.Rear && backCamera != null)
            {
              captureSettings.VideoDeviceId = backCamera.Id; ;
            }
            await MyMediaCapture.InitializeAsync(captureSettings);

            // Assign to Xaml CaptureElement.Source and start preview
            myCaptureElement.Source = MyMediaCapture;

            // show preview
            await MyMediaCapture.StartPreviewAsync();

            // now wait until stopflag shows that someone took a picture
            await t;

            // picture has been taken
            // stop preview

            await CleanUpAsync();

            // go back
            CurrentWindow.Content = originalFrame;

            mainGrid.Children.Remove(this);

            return file;
        }
示例#27
0
        private async void CameraOption(object sender, EventArgs e)
        {
            try
            {
                if (!CrossMedia.Current.IsCameraAvailable || !CrossMedia.Current.IsTakePhotoSupported)
                {
                    await DisplayAlert("No Camera", ":( No camera avaialble.", "OK");

                    return;
                }
                var mediaOptions = new Plugin.Media.Abstractions.StoreCameraMediaOptions
                {
                    Directory = "ShopRConnect",
                    Name      = $"{DateTime.UtcNow}.jpg"
                };

                file = await CrossMedia.Current.TakePhotoAsync(new StoreCameraMediaOptions
                {
                    CompressionQuality = 20,
                    PhotoSize          = PhotoSize.Small
                });

                p           = file.Path;
                FilePathPre = "awsimage" + p;
                FileName    = file.Path;
                FileName    = FileName.Substring(FileName.LastIndexOf("/") + 1);
                FileNamePre = "awsimage" + FileName;
                var content = new MultipartFormDataContent();

                Actimageupload.IsRunning = true;
                await Task.Delay(TimeSpan.FromSeconds(0.01));

                content.Add(new StreamContent(file.GetStream()),
                            "\"file\"",
                            $"\"{file.Path}\"");

                var httpClient = new System.Net.Http.HttpClient();

                // var uploadServiceBaseAddress = "http://maudit.elixirct.net/Uploadfiletoserver/api/Files/Upload";
                var uploadServiceBaseAddress = "http://elixirct.in/ShopRConservicePublish/api/Files/Upload";
                var httpResponseMessage      = await httpClient.PostAsync(uploadServiceBaseAddress, content);

                if (httpResponseMessage.ReasonPhrase.Equals("OK"))
                {
                    MessagingCenter.Send <View.Popup_ImageDialog, string>(this, "awsimagename", FilePathPre);

                    string url = "http://elixirct.in/ShopRConservicePublish/Uploads/" + FileName;
                    await Task.Delay(TimeSpan.FromSeconds(0.01));

                    DependencyService.Get <IFileService>().DownloadFile(url, getGalleryPath());

                    // download.DownloadFile(url, "ShopRConnect");
                    // MessagingCenter.Send<View.Popup_ImageDialog, string>(this, "awsimagename", FileNamePre);

                    await Navigation.PopPopupAsync();

                    Actimageupload.IsRunning = false;
                }
                else
                {
                    await DisplayAlert("Alert", "Network Issue", "OK");

                    Actimageupload.IsRunning = false;
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex);
                //    await DisplayAlert("Alert", "Please check your Internet connection", "Ok");
                Actimageupload.IsRunning = false;
                //   await Navigation.PopPopupAsync();
            }
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="options"></param>
        /// <returns></returns>
        public Intent GetTakePhotoUI(StoreCameraMediaOptions options)
        {
            if (!IsCameraAvailable)
                throw new NotSupportedException();

            VerifyOptions(options);

            int id = GetRequestId();
            return CreateMediaIntent(id, "image/*", MediaStore.ActionImageCapture, options, tasked: false);
        }
示例#29
0
        public virtual async void LoadImages(String[] imageNames, String[] labels = null)
        {
#if NETFX_CORE || (__UNIFIED__ && !__IOS__) //NETFX or Xamarin Mac
            Mat[] mats = new Mat[imageNames.Length];
            for (int i = 0; i < mats.Length; i++)
            {
                mats[i] = CvInvoke.Imread(imageNames[i], ImreadModes.Color);
            }
            InvokeOnImagesLoaded(mats);
#else
            Mat[] mats = new Mat[imageNames.Length];
            for (int i = 0; i < mats.Length; i++)
            {
                String pickImgString = "Use Image from";
                if (labels != null && labels.Length > i)
                {
                    pickImgString = labels[i];
                }
                bool haveCameraOption =
                    (CrossMedia.Current.IsCameraAvailable && CrossMedia.Current.IsTakePhotoSupported);
                bool havePickImgOption =
                    CrossMedia.Current.IsPickVideoSupported;

                String action;
                if (haveCameraOption & havePickImgOption)
                {
                    action = await DisplayActionSheet(pickImgString, "Cancel", null, "Default", "Photo Library",
                                                      "Camera");
                }
                else if (havePickImgOption)
                {
                    action = await DisplayActionSheet(pickImgString, "Cancel", null, "Default", "Photo Library");
                }
                else
                {
                    action = "Default";
                }

                if (action.Equals("Default"))
                {
#if __ANDROID__
                    mats[i] = new Mat(Android.App.Application.Context.Assets, imageNames[i]);
#else
                    mats[i] = CvInvoke.Imread(imageNames[i], ImreadModes.AnyColor);
#endif
                }
                else if (action.Equals("Photo Library"))
                {
#if __ANDROID__ || __IOS__
                    var photoResult = await CrossMedia.Current.PickPhotoAsync();

                    if (photoResult == null) //cancelled
                    {
                        return;
                    }
                    mats[i] = CvInvoke.Imread(photoResult.Path);
#else
                    var file = await CrossMedia.Current.PickPhotoAsync();

                    using (Stream s = file.GetStream())
                        using (MemoryStream ms = new MemoryStream())
                        {
                            s.CopyTo(ms);
                            byte[] data = ms.ToArray();
                            Mat    m    = new Mat();
                            CvInvoke.Imdecode(data, ImreadModes.Color, m);
                            mats[i] = m;
                        }
#endif
                }
                else if (action.Equals("Camera"))
                {
#if __ANDROID__ || __IOS__
                    var mediaOptions = new Plugin.Media.Abstractions.StoreCameraMediaOptions
                    {
                        Directory = "Emgu",
                        Name      = $"{DateTime.UtcNow}.jpg"
                    };
                    var takePhotoResult = await CrossMedia.Current.TakePhotoAsync(mediaOptions);

                    if (takePhotoResult == null) //cancelled
                    {
                        return;
                    }


                    mats[i] = CvInvoke.Imread(takePhotoResult.Path);
#else
                    var file = await CrossMedia.Current.TakePhotoAsync(new StoreCameraMediaOptions());

                    using (Stream s = file.GetStream())
                        using (MemoryStream ms = new MemoryStream())
                        {
                            s.CopyTo(ms);
                            byte[] data = ms.ToArray();
                            Mat    m    = new Mat();
                            CvInvoke.Imdecode(data, ImreadModes.Color, m);
                            mats[i] = m;
                        }
#endif
                }
            }
            InvokeOnImagesLoaded(mats);
#endif
        }
示例#30
0
        public async void PickImage(String defaultImageName)
        {
            await CrossMedia.Current.Initialize();

            String pickImgString = "Use Image from";

            bool haveCameraOption =
                (CrossMedia.Current.IsCameraAvailable && CrossMedia.Current.IsTakePhotoSupported);
            bool havePickImgOption =
                CrossMedia.Current.IsPickVideoSupported;

            String action;

            if (haveCameraOption & havePickImgOption)
            {
                int result = GetUserResponse(this, "Use Image from", "Default", "Photo Library", "Camera");
                if (result == 1)
                {
                    action = "Default";
                }
                else if (result == 0)
                {
                    action = "Photo Library";
                }
                else
                {
                    action = "Camera";
                }
            }
            else if (havePickImgOption)
            {
                int result = GetUserResponse(this, "Use Image from", "Default", "Photo Library", "Cancel");

                if (result == 1)
                {
                    action = "Default";
                }
                else if (result == 0)
                {
                    action = "Photo Library";
                }
                else
                {
                    action = null;
                }
            }
            else
            {
                action = "Default";
            }


            if (action.Equals("Default"))
            {
#if __ANDROID__
                Mat m = new Mat(this.Assets, defaultImageName);
#else
                Mat m = CvInvoke.Imread(defaultImageName);
#endif
                OnImagePicked(this, m);
            }
            else if (action.Equals("Photo Library"))
            {
                var photoResult = await CrossMedia.Current.PickPhotoAsync();

                if (photoResult == null) //cancelled
                {
                    return;
                }
                Mat m = CvInvoke.Imread(photoResult.Path);
                //mats[i] = photoResult.Path;
                OnImagePicked(this, m);
            }
            else if (action.Equals("Camera"))
            {
                var mediaOptions = new Plugin.Media.Abstractions.StoreCameraMediaOptions
                {
                    Directory = "Emgu",
                    Name      = $"{DateTime.UtcNow}.jpg"
                };
                var takePhotoResult = await CrossMedia.Current.TakePhotoAsync(mediaOptions);

                if (takePhotoResult == null) //cancelled
                {
                    return;
                }
                Mat m = new Mat(takePhotoResult.Path);
                OnImagePicked(this, m);
            }
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="options"></param>
        /// <returns></returns>
        public MediaPickerController GetTakePhotoUI(StoreCameraMediaOptions options)
        {
            if (!IsTakePhotoSupported)
                throw new NotSupportedException();
            if (!IsCameraAvailable)
                throw new NotSupportedException();

            VerifyCameraOptions(options);

            var d = new MediaPickerDelegate(null, UIImagePickerControllerSourceType.PhotoLibrary, options);
            return SetupController(d, UIImagePickerControllerSourceType.Camera, TypeImage, options);
        }
        /// <summary>
        /// Take a photo async with specified options
        /// </summary>
        /// <param name="options">Camera Media Options</param>
        /// <returns>Media file of photo or null if canceled</returns>
        public Task<MediaFile> TakePhotoAsync(StoreCameraMediaOptions options)
        {
            if (!IsCameraAvailable)
                throw new NotSupportedException();

            options.VerifyOptions();

            var ntcs = new TaskCompletionSource<MediaFile>(options);
            if (Interlocked.CompareExchange(ref completionSource, ntcs, null) != null)
                throw new InvalidOperationException("Only one operation can be active at a time");

            this.cameraCapture.Show();

            return ntcs.Task;
        }
        private static MediaPickerController SetupController(MediaPickerDelegate mpDelegate, UIImagePickerControllerSourceType sourceType, string mediaType, StoreCameraMediaOptions options = null)
        {
            var picker = new MediaPickerController(mpDelegate);
            picker.MediaTypes = new[] { mediaType };
            picker.SourceType = sourceType;

            if (sourceType == UIImagePickerControllerSourceType.Camera)
            {
                picker.CameraDevice = GetUICameraDevice(options.DefaultCamera);

                if (mediaType == TypeImage)
                    picker.CameraCaptureMode = UIImagePickerControllerCameraCaptureMode.Photo;
                else if (mediaType == TypeMovie)
                {
                    StoreVideoOptions voptions = (StoreVideoOptions)options;

                    picker.CameraCaptureMode = UIImagePickerControllerCameraCaptureMode.Video;
                    picker.VideoQuality = GetQuailty(voptions.Quality);
                    picker.VideoMaximumDuration = voptions.DesiredLength.TotalSeconds;
                }
            }

            return picker;
        }
示例#34
0
        private async void CameraOption(object sender, EventArgs e)
        {
            try
            {
                Actimageupload.IsRunning = true;
                if (!CrossMedia.Current.IsCameraAvailable || !CrossMedia.Current.IsTakePhotoSupported)
                {
                    await DisplayAlert("No Camera", ":( No camera avaialble.", "OK");

                    return;
                }
                var mediaOptions = new Plugin.Media.Abstractions.StoreCameraMediaOptions
                {
                    Directory = "ShopRConnect",
                    Name      = $"{DateTime.UtcNow}.jpg"
                };

                file = await CrossMedia.Current.TakePhotoAsync(new StoreCameraMediaOptions
                {
                    CompressionQuality = 40,
                    PhotoSize          = Plugin.Media.Abstractions.PhotoSize.Medium
                });

                ImagePath = file.Path;
                FileName  = file.Path;
                FileName  = FileName.Substring(FileName.LastIndexOf("/") + 1);

                var content = new MultipartFormDataContent();

                //IFolder rootFolder = await FileSystem.Current.GetFolderFromPathAsync(FileName);
                //var filee = await rootFolder.GetFileAsync(filename2);

                //Stream stream = await filee.OpenAsync(FileAccess.Read);

                //content.Add(new StreamContent(file.GetStream()),
                //    "\"file\"",
                //    $"\"{file.Path}\"");

                //byteData = Model.Convert.ToByteArray(FileName);

                //imlocal = ImageSource.FromStream(this.file.GetStream);

                //var stream = file.GetStream();
                //file.Dispose();
                //var bytes = new byte[stream.Length];
                //await stream.ReadAsync(bytes, 0, (int)stream.Length);
                //string base64 = System.Convert.ToBase64String(bytes);
                //   string base65 = "blobimage" + base64;
                MessagingCenter.Send <View.Popup_OfferImageDialog, string>(this, "blobimagename", ImagePath);
                await Navigation.PopPopupAsync();

                Actimageupload.IsRunning = false;
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex);
                //   await DisplayAlert("Alert", "Please check your Internet connection", "Ok");
                await DisplayAlert("Alert", "Unable to get picture from camera", "Ok");

                Actimageupload.IsRunning = false;
                //   await Navigation.PopPopupAsync();
            }
        }
 private void VerifyCameraOptions(StoreCameraMediaOptions options)
 {
     VerifyOptions(options);
     if (!Enum.IsDefined(typeof(CameraDevice), options.DefaultCamera))
         throw new ArgumentException("options.Camera is not a member of CameraDevice");
 }
        /// <summary>
        /// Take a photo async with specified options
        /// </summary>
        /// <param name="options">Camera Media Options</param>
        /// <returns>Media file of photo or null if canceled</returns>
        public async Task<MediaFile> TakePhotoAsync(StoreCameraMediaOptions options)
        {
            if (!IsCameraAvailable)
                throw new NotSupportedException();

            if (!(await RequestStoragePermission().ConfigureAwait(false)))
            {
                return null;
            }


            VerifyOptions(options);

            var media = await TakeMediaAsync("image/*", MediaStore.ActionImageCapture, options);

            //check to see if we need to rotate if success
            if (!string.IsNullOrWhiteSpace(media?.Path))
            {
                try
                {
                    await FixOrientationAsync(media.Path);
                }
                catch(Exception ex)
                {
                    Console.WriteLine("Unable to check orientation: " + ex);
                }

                if (options.PhotoSize != PhotoSize.Full)
                {
                    try
                    {
                        var bmp = ResizeImage(media.Path, options.PhotoSize);
                        using (var stream = File.Open(media.Path, FileMode.OpenOrCreate))
                            await bmp.CompressAsync(Bitmap.CompressFormat.Png, 92, stream);

                        bmp.Recycle();
                    }
                    catch(Exception ex)
                    {
                        Console.WriteLine("Unable to shrink image: {ex}");
                    }
                }
            }

            return media;
        }
        /// <summary>
        /// Take a photo async with specified options
        /// </summary>
        /// <param name="options">Camera Media Options</param>
        /// <returns>Media file of photo or null if canceled</returns>
        public async Task<MediaFile> TakePhotoAsync(StoreCameraMediaOptions options)
        {
            if (!initialized)
                await Initialize();

            if (!IsCameraAvailable)
                throw new NotSupportedException();

            options.VerifyOptions();

            var capture = new CameraCaptureUI();
            var result = await capture.CaptureFileAsync(CameraCaptureUIMode.Photo, options);
            if (result == null)
                return null;

            StorageFolder folder = ApplicationData.Current.LocalFolder;

            string path = options.GetFilePath(folder.Path);
            var directoryFull = Path.GetDirectoryName(path);
            var newFolder = directoryFull.Replace(folder.Path, string.Empty);
            if (!string.IsNullOrWhiteSpace(newFolder))
                await folder.CreateFolderAsync(newFolder, CreationCollisionOption.OpenIfExists);

            folder = await StorageFolder.GetFolderFromPathAsync(directoryFull);

            string filename = Path.GetFileName(path);

            var file = await result.CopyAsync(folder, filename, NameCollisionOption.GenerateUniqueName).AsTask();
            return new MediaFile(file.Path, () => file.OpenStreamForReadAsync().Result);
        }
        /// <summary>
        /// Take a photo async with specified options
        /// </summary>
        /// <param name="options">Camera Media Options</param>
        /// <returns>Media file of photo or null if canceled</returns>
        public async Task<MediaFile> TakePhotoAsync(StoreCameraMediaOptions options)
        {
            if (!initialized)
                await Initialize();

            if (!IsCameraAvailable)
                throw new NotSupportedException();

            options.VerifyOptions();

            var capture = new CameraCaptureUI();
            capture.PhotoSettings.Format = CameraCaptureUIPhotoFormat.Jpeg;
            capture.PhotoSettings.MaxResolution = CameraCaptureUIMaxPhotoResolution.HighestAvailable;

            var result = await capture.CaptureFileAsync(CameraCaptureUIMode.Photo);
            if (result == null)
                return null;

            StorageFolder folder = ApplicationData.Current.LocalFolder;

            string path = options.GetFilePath(folder.Path);
            var directoryFull = Path.GetDirectoryName(path);
            var newFolder = directoryFull.Replace(folder.Path, string.Empty);
            if (!string.IsNullOrWhiteSpace(newFolder))
                await folder.CreateFolderAsync(newFolder, CreationCollisionOption.OpenIfExists);

            folder = await StorageFolder.GetFolderFromPathAsync(directoryFull);

            string filename = Path.GetFileName(path);

            string aPath = null;
            if (options?.SaveToAlbum ?? false)
            {
                try
                {
                    string fileNameNoEx = Path.GetFileNameWithoutExtension(path);
                    var copy = await result.CopyAsync(KnownFolders.PicturesLibrary, fileNameNoEx + result.FileType, NameCollisionOption.GenerateUniqueName);
                    aPath = copy.Path;
                }
                catch (Exception ex)
                {
                    Debug.WriteLine("unable to save to album:" + ex);
                }
            }

            var file = await result.CopyAsync(folder, filename, NameCollisionOption.GenerateUniqueName).AsTask();
            return new MediaFile(file.Path, () => file.OpenStreamForReadAsync().Result, albumPath: aPath);
        }
        /// <summary>
        /// Take a photo async with specified options
        /// </summary>
        /// <param name="options">Camera Media Options</param>
        /// <returns>Media file of photo or null if canceled</returns>
        public async Task<MediaFile> TakePhotoAsync(StoreCameraMediaOptions options)
        {
            if (!IsCameraAvailable)
                throw new NotSupportedException();

            if (!(await RequestStoragePermission().ConfigureAwait(false)))
            {
                return null;
            }


            VerifyOptions(options);

            var media = await TakeMediaAsync("image/*", MediaStore.ActionImageCapture, options);

            //check to see if we need to rotate if success
            if (!string.IsNullOrWhiteSpace(media?.Path))
                await FixOrientationAsync(media.Path);

            return media;
        }
 /// <summary>
 /// 
 /// </summary>
 /// <param name="options"></param>
 /// <returns></returns>
 public Task<MediaFile> TakePhotoAsync(StoreCameraMediaOptions options)
 {
     return Task.FromResult<MediaFile>(null);
 }
        /// <summary>
        /// Take a photo async with specified options
        /// </summary>
        /// <param name="options">Camera Media Options</param>
        /// <returns>Media file of photo or null if canceled</returns>
        public Task<MediaFile> TakePhotoAsync(StoreCameraMediaOptions options)
        {
            if (!IsTakePhotoSupported)
                throw new NotSupportedException();
            if (!IsCameraAvailable)
                throw new NotSupportedException();

            VerifyCameraOptions(options);

            return GetMediaAsync(UIImagePickerControllerSourceType.Camera, TypeImage, options);
        }