0

我的文本和字体在我的大部分应用程序中看起来都不错;但是,当我执行 .DrawPath() 并且路径在 GraphicsPath 中有一个字符串/文本时,它总是看起来很繁琐或模糊。

有人能告诉我如何让带有字符串的 .DrawPath 看起来像 GrahpicsPath.DrawString 一样漂亮吗?

   //Bay Symbol
   dc.DrawImage(Symbols.GetSymbol(SymbolType.Bay, (i + 1).ToString()), (x + (wPx / 2)) - 10, Constants.ELEVATION_START_Y - 35);




      public static Bitmap GetSymbol(SymbolType symType, string text = "", bool attachLeg = true)
        {
            var sym = new Bitmap(50, 50);
            sym.SetResolution(150, 150);
            using (Graphics dc = Graphics.FromImage(sym))
            {
                dc.SmoothingMode = SmoothingMode.AntiAlias;
                switch (symType)
                {

                  //code removed for clarity

                    case SymbolType.Bay:
                        dc.DrawPath(ShopDrawing.Pens.GetSymbolPen(), CreateBaySymbol(text));
                        if (attachLeg)
                            AttachSymbolLeg(dc, Constants.BAY_SYMBOL);
                        break;
                };
                dc.SmoothingMode = SmoothingMode.Default;

                return sym;
            }
        }



       internal static GraphicsPath CreateBaySymbol(string text = "")
        {
            GraphicsPath myPath = new GraphicsPath();

            myPath.AddRectangle(Constants.BAY_SYMBOL);
            if (!string.IsNullOrEmpty(text)) { Util.AddStringToPath(myPath, text); }

            return myPath;
        }

      internal static void AddStringToPath(GraphicsPath path, string text)
        {
            var textSize = TextRenderer.MeasureText(text, Constants.DETAIL_BOX_FONT);

            float centerX = (path.GetBounds().Width / 2) - (textSize.Width / 2),
                  centerY = (path.GetBounds().Height / 2) - (textSize.Height / 2);

            //Add the string to the path.
            path.AddString(text,
                                Constants.DETAIL_BOX_FONT.FontFamily,
                           (int)Constants.DETAIL_BOX_FONT.Style,
                                Constants.DETAIL_BOX_FONT.Size,
                                new PointF(centerX + 2, centerY + 2),
                                StringFormat.GenericDefault)

符号 = 对下面高程的每个部分进行编号的符号。您可以看到编号如何从 1 开始,然后是 2,然后是 3,依此类推。

这是一个快照,显示了所有字体/文本的外观,如宽度和高度的数字,但符号内的编号看起来很糟糕。

带有文本的图形 DrawPath 模糊

4

0 回答 0