取得GraphicsPath的源码

时间:2022-06-06 00:38:02
private string OutputGraphicsPath(GraphicsPath gp)

{

StringBuilder sb = new StringBuilder();

GraphicsPathIterator gpi = new GraphicsPathIterator(gp);

int start, end, count = 0;

count = gpi.NextMarker(out start, out end);

PointF[] points = new PointF[count];

byte[] types = new byte[count];

gpi.CopyData(ref points, ref types, start, end);

sb.Append(string.Format("GraphicsPath path{0} = new GraphicsPath(\r\n", 0));

sb.Append("new PointF[] {\r\n");

for (int i = 0; i < points.Length; i++)

{

sb.Append(String.Format("new PointF({0}F,{1}F)", points[i].X, points[i].Y));

if (i != points.Length - 1) sb.Append(",");

if ((i + 1) % 5 == 0) sb.Append("\r\n");

}

sb.Append(@"},

new System.Byte[] {

");

for (int i = 0; i < types.Length; i++)

{

sb.Append(types[i].ToString());

if (i != types.Length - 1) sb.Append(",");

if ((i + 1) % 20 == 0) sb.Append("\r\n");

}

sb.Append(" });\r\n");

//resultGP.AddPath(gp, false);

//g.FillPath(Brushes.Red, gp);

//sb.Append(gp.ToString());

return sb.ToString();

}