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); }