Ejemplo n.º 1
0
        public async Task ShowEmoji(DrawingContext drawingContext, Rect face, string emocao)
        {
            //var emoji = new PictureBox();
            //emoji.BackgroundImageLayout = ImageLayout.Stretch;
            //emoji.BackColor = System.Drawing.Color.Transparent;
            //emoji.Height = 74;
            //emoji.Width = 74;
            //emoji.Location = new System.Drawing.Point((int)x, (int)y);
            //emoji.BackgroundImage = GetEmojiBipMap(emocao);

            //Task.Run(() => ExecuteSecure(control, () => control.Controls.Add(emoji)));

            drawingContext.DrawImage(DisplayEmotion.ImageSourceForBitmap(DisplayEmotion.GetEmojiBipMap(emocao)), face);
        }
Ejemplo n.º 2
0
        public static BitmapSource DrawFaces(BitmapSource baseImage, Microsoft.ProjectOxford.Face.Contract.Face[] faces, EmotionScores[] emotionScores, string[] celebName, Control form)
        {
            if (faces == null)
            {
                return(baseImage);
            }

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

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

                    string text = "";

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

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

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

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

                    double lineThickness = 4 * annotationScale;

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


                    ClearEmojis(form);

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

                        var pad = 6 * annotationScale;

                        var ypad   = pad;
                        var xpad   = pad + 10 * 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);

                        var x = baseImage.DpiX + faceRect.X;
                        var y = baseImage.DpiY + faceRect.Y;



                        Console.WriteLine("------------------");
                        Console.WriteLine("baseImage width:  " + baseImage.Width);
                        Console.WriteLine("form width:  " + form.Width);
                        Console.WriteLine("faceRect width:  " + faceRect.Width);
                        Console.WriteLine("ft width:  " + ft.Width);
                        Console.WriteLine("x:  " + x);
                        Console.WriteLine("y:  " + y);
                        Console.WriteLine("------------------");


                        var originEmoji = new System.Windows.Point(
                            faceRect.Left + lineThickness,
                            faceRect.Top - ((ft.Height - ypad + lineThickness / 2) * 8));

                        Rect rectEmoji = new Rect(originEmoji, new Size(90, 90));
                        drawingContext.DrawRectangle(null, null, rectEmoji);

                        var displayEmoji = new DisplayEmotion();
                        displayEmoji.ShowEmoji(drawingContext, rectEmoji, text);
                    }
                }
            };

            return(DrawOverlay(baseImage, drawAction));
        }