【问题标题】:Using Angus J Clipper library to outline GraphicsPath text in vb.net使用 Angus J Clipper 库在 vb.net 中勾勒 GraphicsPath 文本
【发布时间】:2012-09-18 15:40:07
【问题描述】:

我正在使用 DrawString 在 GDI+ GraphicsPath 中创建文本,然后将其作为路径输出到 PDF。

目前一切正常。

我遇到问题的时间是所选字体导致轮廓相互重叠。我有一个图片示例,虽然是一个新用户,但我无法上传它......(似乎毫无意义......?......)

我找到了一个library 以及一个与我在这个blog 中寻找的目标相同的人

我已将代码 sn-p 转换为 vb.net,尽管我不断从库中得到一个空的解决方案。

是否有其他人设法传入包含字符串的 graphicsPath 并使用此库或类似库检索轮廓文本?

【问题讨论】:

  • 我设法通过使用 ClipType.ctUnion 来从博客中获取代码。非常快的图书馆。我在下面标记了答案,因为该代码也有效;只是博客中的那个更简单,更有效地满足了我的需求。

标签: vb.net gdi+ polygon outline graphicspath


【解决方案1】:

这是一些有效的 C# 代码...

    using ClipperLib;

    static public void PathToPolygon(GraphicsPath path, Polygons polys, Single scale)
    {
        GraphicsPathIterator pathIterator = new GraphicsPathIterator(path);
        pathIterator.Rewind();
        polys.Clear();
        PointF[] points = new PointF[pathIterator.Count];
        byte[] types = new byte[pathIterator.Count];
        pathIterator.Enumerate(ref points, ref types);
        int i = 0;
        while (i < pathIterator.Count)
        {
            Polygon pg = new Polygon();
            polys.Add(pg);
            do {

                IntPoint pt = new IntPoint((int)(points[i].X * scale), (int)(points[i].Y * scale));
                    pg.Add(pt);
                i++;
            }
            while (i < pathIterator.Count && types[i] != 0);
        }
    }


    static private PointF[] PolygonToPointFArray(Polygon pg, float scale)
    {
        PointF[] result = new PointF[pg.Count];
        for (int i = 0; i < pg.Count; ++i)
        {
            result[i].X = (float)pg[i].X / scale;
            result[i].Y = (float)pg[i].Y / scale;
        }
        return result;
    }


    private void DrawBitmap()
    {
        Font f = new Font("Arial", 90);
        Pen myPen = new Pen(Color.FromArgb(196, 0xC3, 0xC9, 0xCF), (float)0.6);
        SolidBrush myBrush = new SolidBrush(Color.FromArgb(127, 0xDD, 0xDD, 0xF0));
        path.Reset();
        Polygons polys;
        path.AddString("ABC", f.FontFamily, (int)f.Style, f.Size, new Point(100, 100), null);
        path.Flatten();
        //scale all points up by 100 because Clipper uses integer coordinates
        PathToPolygon(path, polys, 100);
        path.Reset();
        //offset polys remembering to multiply delta by scaling amount ...
        polys = Clipper.OffsetPolygons(polys, 7 * 100, JoinType.jtRound);
        for (int i = 0; i < polys.Count(); i++)
        {
            //reverses scaling ...
            PointF[] pts2 = PolygonToPointFArray(polys[i], 100);
            path.AddPolygon(pts2);
        }
        newgraphic.FillPath(myBrush, path);
        newgraphic.DrawPath(myPen, path);
    }

【讨论】:

  • 谢谢安格斯。只是试图转换代码,虽然有点麻烦......知道这是如何在 vb 中完成的吗?使用 Polygon = List;再次感谢
  • 抱歉,Darren,我从未接触过 VB。
  • 没问题,谢谢。我设法转换了代码,尽管我的 Q 中的代码也可以正常工作——必须使用 ClipType.ctUnion。它的工作速度如此之快!你在那里建立了一个很棒的图书馆:)
  • 是的,我将轮廓误读为偏移量,因此,当然,“合并”多边形正是您需要做的。无论如何,感谢您对我的 Clipper 库的鼓励反馈。
猜你喜欢
  • 2012-07-04
  • 1970-01-01
  • 2013-12-18
  • 1970-01-01
  • 2010-12-08
  • 1970-01-01
  • 2022-06-10
  • 1970-01-01
  • 2013-05-04
相关资源
最近更新 更多