private async Task <FaceDetection> DetectFaceAsync(MediaFile inputFile)
        {
            if (!CrossConnectivity.Current.IsConnected)
            {
                await DisplayAlert("ネットワークエラー", "ネット接続を確認してからリトライしてください。", "OK");

                return(null);
            }

            try
            {
                var faces = await _faceServiceClient.DetectAsync(inputFile.GetStream(), false, false, (FaceAttributeType[])Enum.GetValues(typeof(FaceAttributeType)));

                if (faces.Length == 0)
                {
                    throw new Exception("顔を認識できませんでした。別の写真を試してください。");
                }

                var faceAttributes = faces[0]?.FaceAttributes;
                var faceDetection  = new FaceDetection();
                faceDetection.Age       = faceAttributes.Age;
                faceDetection.Emotion   = faceAttributes.Emotion.ToRankedList().FirstOrDefault().Key;
                faceDetection.Glasses   = faceAttributes.Glasses.ToString();
                faceDetection.Smile     = faceAttributes.Smile;
                faceDetection.Gender    = faceAttributes.Gender;
                faceDetection.Moustache = faceAttributes.FacialHair.Moustache;
                faceDetection.Beard     = faceAttributes.FacialHair.Beard;

                faceDetection.Anger     = faceAttributes.Emotion.Anger;
                faceDetection.Contempt  = faceAttributes.Emotion.Contempt;
                faceDetection.Disgust   = faceAttributes.Emotion.Disgust;
                faceDetection.Fear      = faceAttributes.Emotion.Fear;
                faceDetection.Happiness = faceAttributes.Emotion.Happiness;
                faceDetection.Neutral   = faceAttributes.Emotion.Neutral;
                faceDetection.Sadness   = faceAttributes.Emotion.Sadness;
                faceDetection.Surprise  = faceAttributes.Emotion.Surprise;

                return(faceDetection);
            }
            catch (Exception ex)
            {
                await DisplayAlert("Error", ex.Message, "OK");

                return(null);
            }
        }
        private async void UploadPictureButton_Clicked(object sender, EventArgs e)
        {
            if (!CrossMedia.Current.IsPickPhotoSupported)
            {
                await DisplayAlert("アップロードできません", "この端末は写真の選択をサポートしていません", "OK");

                return;
            }
            var file = await CrossMedia.Current.PickPhotoAsync();

            if (file == null)
            {
                return;
            }
            Indicator1.IsRunning = true;
            Image1.Source        = ImageSource.FromStream(() => file.GetStream());
            FaceDetection theData = await DetectFaceAsync(file);

            BindingContext       = theData;
            Indicator1.IsRunning = false;
        }