Ejemplo n.º 1
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"
                        });
                    }
                }
            }
        }