private BitmapSource DrawFacesContext(BitmapSource baseImage, IReadOnlyList <Face> faces,
                                              IReadOnlyList <EmotionScores> emotionScores, IReadOnlyList <string> celebName)
        {
            if (faces == null)
            {
                return(baseImage);
            }

            void DrawAction(DrawingContext drawingContext, double annotationScale)
            {
                for (var i = 0; i < faces.Count; i++)
                {
                    var face = faces[i];
                    if (face.FaceRectangle == null)
                    {
                        continue;
                    }

                    var faceRect = new Rect(face.FaceRectangle.Left, face.FaceRectangle.Top, face.FaceRectangle.Width,
                                            face.FaceRectangle.Height);
                    var text = "";

                    if (face.FaceAttributes != null)
                    {
                        text += _faceService.SummarizeFaceAttributes(face.FaceAttributes);
                    }

                    if (emotionScores?[i] != null)
                    {
                        text += _emotionService.SummarizeEmotionScores(emotionScores[i]);
                    }

                    if (celebName?[i] != null)
                    {
                        text += celebName[i];
                    }

                    faceRect.Inflate(6 * annotationScale, 6 * annotationScale);

                    var lineThickness = 4 * annotationScale;

                    drawingContext.DrawRectangle(Brushes.Transparent, new Pen(_sLineBrush, lineThickness), faceRect);

                    if (text == "")
                    {
                        continue;
                    }
                    var ft = new FormattedText(text, CultureInfo.CurrentCulture, FlowDirection.LeftToRight, _sTypeface,
                                               16 * annotationScale, Brushes.Black);

                    var pad = 3 * annotationScale;

                    var ypad   = pad;
                    var xpad   = pad + 4 * annotationScale;
                    var origin = new Point(faceRect.Left + xpad - lineThickness / 2,
                                           faceRect.Top - ft.Height - ypad + lineThickness / 2);
                    var rect = ft.BuildHighlightGeometry(origin).GetRenderBounds(null);
                    rect.Inflate(xpad, ypad);

                    drawingContext.DrawRectangle(_sLineBrush, null, rect);
                    drawingContext.DrawText(ft, origin);
                }
            }

            return(DrawOverlay(baseImage, DrawAction));
        }
        private BitmapSource DrawFacesContext(BitmapSource baseImage, Microsoft.ProjectOxford.Face.Contract.Face[] faces, EmotionScores[] emotionScores, string[] celebName)
        {
            if (faces == null)
            {
                return(baseImage);
            }

            Action <DrawingContext, double> drawAction = (drawingContext, annotationScale) =>
            {
                for (int i = 0; i < faces.Length; i++)
                {
                    var face = faces[i];
                    if (face.FaceRectangle == null)
                    {
                        continue;
                    }

                    var faceRect = new Rect(
                        face.FaceRectangle.Left, face.FaceRectangle.Top,
                        face.FaceRectangle.Width, face.FaceRectangle.Height);
                    string text = "";

                    if (face.FaceAttributes != null)
                    {
                        text += _faceService.SummarizeFaceAttributes(face.FaceAttributes);
                    }

                    if (emotionScores?[i] != null)
                    {
                        text += _emotionService.SummarizeEmotionScores(emotionScores[i]);
                    }

                    if (celebName?[i] != null)
                    {
                        text += celebName[i];
                    }

                    faceRect.Inflate(6 * annotationScale, 6 * annotationScale);

                    var lineThickness = 4 * annotationScale;

                    drawingContext.DrawRectangle(
                        Brushes.Transparent,
                        new Pen(s_lineBrush, lineThickness),
                        faceRect);

                    if (text != "")
                    {
                        var ft = new FormattedText(text,
                                                   CultureInfo.CurrentCulture, FlowDirection.LeftToRight, s_typeface,
                                                   16 * annotationScale, Brushes.Black);

                        var pad = 3 * annotationScale;

                        var ypad   = pad;
                        var xpad   = pad + 4 * annotationScale;
                        var origin = new System.Windows.Point(
                            faceRect.Left + xpad - lineThickness / 2,
                            faceRect.Top - ft.Height - ypad + lineThickness / 2);
                        var rect = ft.BuildHighlightGeometry(origin).GetRenderBounds(null);
                        rect.Inflate(xpad, ypad);

                        drawingContext.DrawRectangle(s_lineBrush, null, rect);
                        drawingContext.DrawText(ft, origin);
                    }
                }
            };

            return(DrawOverlay(baseImage, drawAction));
        }