Example #1
0
        public static string Avatar(FaceBase face)
        {
            if (face.Gender == Gender.Unknown || face.Age == Age.Age_Unknown)
            {
                return(string.Empty);
            }
            StringBuilder path = new StringBuilder($@".\emojiData\avatar\{face.Gender.ToString()}\");

            switch (face.Age)
            {
            default:
            case Age.Age_Under_18:
            case Age.Age_18_24:
                path.Append(@"0-24\");
                break;

            case Age.Age_25_34:
            case Age.Age_35_44:
            case Age.Age_45_54:
                path.Append(@"25-54\");
                break;

            case Age.Age_55_64:
            case Age.Age_65_Plus:
                path.Append(@"55+\");
                break;
            }
            path.Append(face.Ethnicity.ToString());
            path.Append(".png");
            return(path.ToString());
        }
Example #2
0
        public static string DescribeIndexDetail(FaceBase face)
        {
            string[] ns0 =
            {
                "生气指数有点高,生气显老啊!",
                "傲娇指数高企啊~哼~",
                "今天遇到\"不可描述\"的事情?",
                $"别{(face.Gender == Gender.Male ? "怂" : "怕")},我在!",
                "开心的你最可爱",
                "宝宝你别哭",
                "收到礼物了?"
            };
            string[] ns1 =
            {
                "生气指数有点高,好气啊!",
                "傲娇指数高企啊~哼~",
                "发生什么事情了O_O?",
                $"恐惧指数爆棚..好恐怖T^T",
                "猴开熏~~~",
                "伤心绝顶QwQ求抱抱",
                "Surprise!"
            };
            string[][] ns  = { ns0, ns1 };
            int        idx = face.DominantEmotionIndex;

            if (idx < 0)
            {
                return("\"我的内心毫无波澜\"");
            }
            return(ns[Global.Random.Next(ns.Length)][idx]);
        }
Example #3
0
        public static string DescribeFace(FaceBase face)
        {
            StringBuilder sb = new StringBuilder();

            switch (face.Gender)
            {
            case Gender.Female:
                string[] d0 =
                {
                    "???",
                    "娇娥",
                    "淑女",
                    "婵娟",
                    "巾帼",
                    "裙钗",
                    "夫人",
                    "罗敷",
                };
                sb.Append(d0[(int)face.Age]);
                break;

            case Gender.Male:
                sb.Append($"{face.Age} 汉子!");
                break;

            default:
                sb.Append("此脸只应天上有~");
                break;
            }
            return(sb.ToString());
        }
Example #4
0
        public static string DescribEmoji(FaceBase face)
        {
            StringBuilder sb = new StringBuilder(@".\emojiData\");

            if (face.DominantEmoji != Emoji.Unknown)
            {
                sb.Append($@"emoji\{face.DominantEmoji}\");
            }
            else
            {
                sb.Append(@"emotion\");
                int idx = face.DominantEmotionIndex;
                if (idx < 0)
                {
                    sb.Append(@"Null\");
                }
                else
                {
                    sb.Append($@"{RawDataName(idx)}\");
                }
            }
            string path = Path.Combine(".\\", sb.ToString());

            sb.Append(DirectoryHelper.RandomFile(path));
            sb.Append(".png");
            return(sb.ToString());
        }
Example #5
0
 public Image Draw(FaceBase face, Image org)
 {
     int IdxHeight = org.Height / 4;
     int ExtHeight = org.Width / 8;
     double extw = (9.0 / 16.0) * (org.Height + IdxHeight + ExtHeight) - org.Width;
     int ExtWidth = Math.Max(org.Width / 8, (int)Math.Ceiling(extw));
     Image Handled = new Bitmap(org.Width + ExtWidth, org.Height + ExtHeight + IdxHeight);
     using (Graphics g = Graphics.FromImage(Handled))
     {
         g.TextRenderingHint = TextRenderingHint.AntiAlias;
         g.CompositingQuality = CompositingQuality.HighQuality;
         g.CompositingMode = CompositingMode.SourceOver;
         g.SmoothingMode = SmoothingMode.HighQuality;
         g.PixelOffsetMode = PixelOffsetMode.HighQuality;
         g.InterpolationMode = InterpolationMode.High;
         // draw base
         g.FillRectangle(Brushes.White, new Rectangle(Point.Empty, Handled.Size));
         g.DrawImagePixel(org, new PointF(ExtWidth / 2.0f, ExtHeight / 2.0f));
         // draw desc
         g.TranslateTransform(ExtWidth / 2.0f, ExtHeight / 2.0f);
         DrawDesc(g, face, org.Size);
         // draw index
         g.ResetTransform();
         g.TranslateTransform(ExtWidth / 2.0f, org.Height + ExtHeight / 2.0f);
         DrawIndex(g, face, new Size(org.Width, IdxHeight));
         // draw copyright
         g.ResetTransform();
         DrawCopyright(g, Handled.Size);
     }
     return Handled;
 }
Example #6
0
        private void DrawIndex(Graphics g, FaceBase face, Size size)
        {
            GraphicsState gstate = g.Save();

            SizeF tSize        = new SizeF(size.Width, size.Height / 3f);
            Color emotionColor = Describer.EmotionColor(face);

            Font  font;
            SizeF fsize;
            // header
            string header = $"{DateTime.Now.ToString("MM月dd日")}心情指数:";

            MatchFontSize(g, tSize.Width, tSize.Height, header, out font, out fsize);
            g.DrawOutlineString(header, font, emotionColor, Color.Black, PointF.Empty);
#if DEBUG
            g.DrawRectangles(Pens.Red, new RectangleF[] { new RectangleF(PointF.Empty, fsize) });
#endif
            // detail
            string etext = Describer.DescribeIndexDetail(face);
            MatchFontSize(g, tSize.Width, tSize.Height, etext, out font, out fsize);
            PointF loc = new PointF(size.Width - fsize.Width, tSize.Height * 2);
            g.DrawOutlineString(etext, font, emotionColor, Color.Black, loc, 0.125f, true);
#if DEBUG
            g.DrawRectangles(Pens.Red, new RectangleF[] { new RectangleF(loc, fsize) });
#endif
            // emoji
            float left = (size.Width - fsize.Width) / 2;
            using (Image emoji = Image.FromFile(Describer.DescribEmoji(face)))
            {
                g.DrawImage(emoji,
                            new RectangleF(left, tSize.Height, tSize.Height, tSize.Height),
                            new RectangleF(0, 0, emoji.Width, emoji.Height),
                            GraphicsUnit.Pixel);
            }

            int pid = DirectoryHelper.RandomFile(Path.Combine(Global.ServerRoot, @"Content\progress"));
            using (Image progess = Image.FromFile(Path.Combine(Global.ServerRoot, $@"Content\progress\{pid}.png")))
                using (Image progessx = Image.FromFile(Path.Combine(Global.ServerRoot, $@"Content\progressx\{pid}.png")))
                {
                    float ratio = tSize.Height / progess.Height;
                    DrawImageMappingColor(g, progess, Color.FromArgb(192, 192, 192),
                                          new RectangleF(left + tSize.Height, tSize.Height, progess.Width * ratio, tSize.Height),
                                          new RectangleF(0, 0, progess.Width, progess.Height));

                    float cw = progess.Width * (float)Math.Pow(face.DominantEmotion / 100, 1 / 3.0);
                    if (face.DominantEmotionIndex < 0)
                    {
                        cw = progess.Width;
                    }
                    DrawImageMappingColor(g, progess, emotionColor,
                                          new RectangleF(left + tSize.Height, tSize.Height, cw * ratio, tSize.Height),
                                          new RectangleF(0, 0, cw, progess.Height));

                    DrawImageMappingColor(g, progessx, Color.Black,
                                          new RectangleF(left + tSize.Height, tSize.Height, progessx.Width * ratio, tSize.Height),
                                          new RectangleF(0, 0, progessx.Width, progessx.Height));
                }

            g.Restore(gstate);
        }
Example #7
0
        private void DrawDesc(Graphics g, FaceBase face, Size size)
        {
            GraphicsState gstate = g.Save();
            
            CircleF circle = face.EnclosingCircle();
            Color outlineColor = Describer.GenderColor(face);

            using (Image mask = MaskImage(size, circle, Color.FromArgb(128, 255, 255, 255)))
                g.DrawImagePixel(mask);

#if DEBUG
            g.DrawCircle(Pens.Red, circle.Center.X, circle.Center.Y, circle.Radius);
#endif

            string text = Describer.DescribeFace(face);

            Font font = new Font(pfc.Families[0], 24);
            SizeF fsize = g.MeasureString(text, font);
            double fratio = fsize.Height / fsize.Width;

            double goldenAngle = ((9 * rand.NextDouble() + 4.5) * (rand.Next(2) * 2 - 1)) * Math.PI / 180;
            float mxlen;
            PointF center;
            MaxTextRegion(
                size, new CircleF(circle.Center, circle.Radius),
                goldenAngle, fratio,
                out mxlen, out center);

            MatchFontSize(g, mxlen, float.MaxValue, text, out font, out fsize);

            g.TransformRectToFixSeg(
                center,
                (float)(goldenAngle * 180 / Math.PI), mxlen,
                fsize.Width, fsize.Height);

            float faceR = fsize.Height / 2;
            string avatarPath = Describer.Avatar(face);
            if (string.IsNullOrEmpty(avatarPath))
                g.DrawOutlineString(text, font, Color.White, outlineColor, PointF.Empty);
            else
            {
                Size ss = new Size((int)fsize.Height, (int)fsize.Height);
                using (Bitmap
                    org = new Bitmap(avatarPath),
                    img = new Bitmap(org, ss))
                {
                    int d = rand.Next(2);
                    g.DrawOutlineString(text, font, Color.White, outlineColor, new PointF(faceR * (1 - d * 2), 0));
                    g.DrawImagePixel(img, new PointF(fsize.Width * d - faceR, 0));
                }
            }
#if DEBUG
            g.DrawCircle(Pens.Yellow, fsize.Width, faceR, faceR);
            g.DrawCircle(Pens.Yellow, 0, faceR, faceR);
            g.DrawRectangles(Pens.Red, new RectangleF[] { new RectangleF(PointF.Empty, fsize) });
#endif

            g.Restore(gstate);
        }
Example #8
0
 private static string DescribeFaceOnlyGender(FaceBase face)
 {
     if (face.Gender == Gender.Female)
     {
         return("妹纸");
     }
     else if (face.Gender == Gender.Male)
     {
         return("汉子");
     }
     else
     {
         return("如果你看到这句话说明服务器炸了");
     }
 }
Example #9
0
        public static Color GenderColor(FaceBase face)
        {
            switch (face.Gender)
            {
            default:
            case Gender.Unknown:
                return(Color.Black);

            case Gender.Male:
                return(Color.DodgerBlue);

            case Gender.Female:
                return(Color.Plum);
            }
        }
Example #10
0
        public static Color EmotionColor(FaceBase face)
        {
            Color[] cs =
            {
                Color.FromArgb(218,    83,  44),
                Color.LightSlateGray,
                Color.FromArgb(255,   153,  180,51),
                Color.LightSalmon,
                Color.FromArgb(255,   196,  13),
                Color.FromArgb(43,     87, 151),
                Color.FromArgb(126,    56, 120)
            };
            int idx = face.DominantEmotionIndex;

            if (idx < 0)
            {
                return(Color.FromArgb(0, 171, 169));
            }
            return(cs[idx]);
        }
Example #11
0
        private static string DescribeFaceFullInfo(FaceBase face)
        {
            if (face.Age == Age.Age_Under_18)
            {
                return($"萌萌哒{(face.Gender == Gender.Female ? "萝莉" : "正太")}");
            }
            if (face.Gender == Gender.Female)
            {
                string[] t = { "娇娥", "淑女", "裙钗", "罗敷" };
                return(t[Global.Random.Next(t.Length)]);
            }
            else
            {
                switch (face.Age)
                {
                case Age.Age_18_24:
                    return("弱冠美男子");

                case Age.Age_25_34:
                    return("而立男儿");

                case Age.Age_35_44:
                    return("不惑汉子");

                case Age.Age_45_54:
                    return("知命汉子");

                case Age.Age_55_64:
                    return("花甲汉子");

                case Age.Age_65_Plus:
                    return("古稀汉子");

                default:
                case Age.Age_Unknown:
                case Age.Age_Under_18:
                    return("如果你看到这句话说明服务器炸了");
                }
            }
        }
Example #12
0
        public static string DescribeIndexDetail(FaceBase face)
        {
            string[] ns =
            {
                "生气显老啊!",
                "傲娇~哼~",
                "今天遇到不可描述的事情?",
                //"Engagement",
                $"别{(face.Gender==Gender.Male?"怂":"怕")},我在!",
                "开心的你最可爱",
                "宝宝你别哭",
                "收到礼物了?",
                //"Valence"
            };
            int idx = face.DominantEmotionIndex;

            if (idx < 0)
            {
                return("\"我的内心毫无波澜\"");
            }
            return(ns[idx]);
        }
Example #13
0
        public static string DescribeIndex(FaceBase face)
        {
            string[] ns =
            {
                "好气啊!",
                "你看我理你?",
                "厌恶~",
                //"Engagement",
                "好方QAQ",
                "愉快~lalal~",
                "伤心T^T",
                "惊奇!",
                //"Valence"
            };
            int idx = face.DominantEmotionIndex;

            if (idx < 0)
            {
                return("自然");
            }
            return(ns[idx]);
        }
Example #14
0
        public static Color EmotionColor(FaceBase face)
        {
            Color[] cs =
            {
                Color.Crimson,
                Color.LightSlateGray,
                Color.YellowGreen,
                //Color.CornflowerBlue,
                Color.Salmon,
                Color.Gold,
                Color.CornflowerBlue,
                Color.MediumOrchid,
                //Color.Purple
            };
            int idx = face.DominantEmotionIndex;

            if (idx < 0)
            {
                return(Color.Aquamarine);
            }
            return(cs[idx]);
        }
Example #15
0
        public static string DescribeFace(FaceBase face)
        {
            // know nothing
            if (face.Age == Age.Age_Unknown &&
                face.Gender == Gender.Unknown)
            {
                return("此脸只应天上有~");
            }

            // only gender
            if (face.Age == Age.Age_Unknown)
            {
                return(DescribeFaceOnlyGender(face));
            }

            // only age
            if (face.Gender == Gender.Unknown)
            {
                return(DescribeFaceOnlyAge(face));
            }

            // full info
            return(DescribeFaceFullInfo(face));
        }
Example #16
0
        private static string DescribeFaceOnlyAge(FaceBase face)
        {
            switch (face.Age)
            {
            case Age.Age_Under_18:
            case Age.Age_18_24:
                return("年轻就是好");

            case Age.Age_25_34:
                return("要朝气蓬勃啊");

            case Age.Age_35_44:
            case Age.Age_45_54:
                return("成熟稳重");

            case Age.Age_55_64:
            case Age.Age_65_Plus:
                return("要神采奕奕哟");

            default:
            case Age.Age_Unknown:
                return("如果你看到这句话说明服务器炸了");
            }
        }
Example #17
0
 public DetectAdapterEventAgrs(FaceBase face)
 {
     Face = face;
 }