graphics 的DrawText 与graphicspath 的addstring的区别

来源:互联网 发布:波士顿动力 知乎 编辑:程序博客网 时间:2024/06/05 02:54

 graphicspath 的addstring() 表示向此路径添加文本字符串。

然后用graphics的Drawpath()生成字体,发现是空心的。而用graphics的fillpath()生成的字体是实心的。

而这两个生成的字体不如用drawtext生成的字体看着好。必竟前者相当于填充画图。

            Pen pen = new Pen(Color);
            Brush b = new SolidBrush(Color);
            StringFormat sf = new StringFormat();
            sf.Trimming = StringTrimming.Word;


            GraphicsPath gp = new GraphicsPath();

            //gp.AddString(_theText, _font.FontFamily, (int)_font.Style, _font.SizeInPoints,
            // new PointF(Rectangle.X, Rectangle.Y), StringFormat.GenericDefault);
            gp.AddString(_theText, _font.FontFamily, (int)_font.Style, _font.SizeInPoints,
                       new RectangleF(rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height), sf);


            // Rotate the path about it's center if necessary

            if (Rotation != 0)
            {
                RectangleF pathBounds = gp.GetBounds();
                Matrix m = new Matrix();
                m.RotateAt(Rotation, new PointF(pathBounds.Left + (pathBounds.Width / 2), pathBounds.Top + (pathBounds.Height / 2)),
                           MatrixOrder.Append);
                // gp.Transform(m);
               g.Transform = m;
            }

          

            //g.DrawString(_theText, _font, b, new PointF(Rectangle.X, Rectangle.Y),sf);
            g.DrawString(_theText, _font, b, new RectangleF(rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height), sf);

           // g.DrawPath(pen, gp);
          //  g.FillPath(b, gp);
            // rectangle.Size = g.MeasureString(_theText, _font).ToSize();