コード例 #1
0
        private async void OnAnalyzeFaces(object sender, EventArgs e)
        {
            if (_photo == null)
            {
                return;
            }
            EnableAllButtons(false);
            try
            {
                IList <DetectedFace> faces = await FaceDetection.MakeAnalysisRequest(_photo);

                DetectedFace face = faces.FirstOrDefault();
                ActivityIndicator.IsRunning = false;
                if (face == null)
                {
                    await DisplayAlert("Face Analysis", "No Faces Found", "OK");

                    return;
                }
                string smiling  = face.FaceAttributes.Smile >= 0.75 ? "smiling" : "not smiling";
                var    analysis = $"{face.FaceAttributes.Age} year old {face.FaceAttributes.Gender} who is {smiling}.";
                await DisplayAlert("Face Analysis", analysis, "OK");
            }
            catch (Exception ex)
            {
                await DisplayAlert("Analysis Error", ex.Message, "OK");
            }
            finally
            {
                EnableAllButtons(true);
            }
        }