Example #1
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.PluginRoot, @"Content\progress"));
            using (Image progess = Image.FromFile(Path.Combine(Global.PluginRoot, $@"Content\progress\{pid}.png")))
                using (Image progessx = Image.FromFile(Path.Combine(Global.PluginRoot, $@"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 #2
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 range       = Global.Random.NextDouble();
            int    dir         = Global.Random.Next(2);
            double goldenAngle = ((9 * range + 4.5) * (dir * 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 = Global.Random.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);
        }