0
点赞
收藏
分享

微信扫一扫

将GraphicsPath转为SVG代码


GraphicsPathToSVG(c#代码)

     

public static string GraphicsPathToSVG(GraphicsPath path)
{
PathData pathData = path.PathData;
StringBuilder def = new System.Text.StringBuilder();
int i = 0; byte bytType;
int cCount = 0; string strX = null;
string strY = null; def.Append("<path ");
//if (IncludeId) def.Append("id=\"\" ");
def.Append("fill-rule=\"evenodd\"");
def.Append(" style=\"fill:orange;stroke:red;stroke-width:1\" d=\""); for (i = 0; i <= pathData.Points.GetUpperBound(0); i++)
{
bytType = pathData.Types[i];
strX = XmlConvert.ToString(Math.Round(pathData.Points[i].X, 2));
strY = XmlConvert.ToString(Math.Round(pathData.Points[i].Y, 2)); if (bytType == 0) //Moveto
{
def.Append("M ");
def.Append(strX);
def.Append(",");
def.Append(strY);
def.Append(" ");
cCount = 0;
}
else
{
if (bytType == 1) //Lineto
{
def.Append("L ");
def.Append(strX);
def.Append(",");
def.Append(strY);
def.Append(" ");
cCount = 0;
}
else
{
if (bytType > 128) //lineto or curve and closepath
{
if (cCount == 0)
def.Append("L ");
def.Append(strX);
def.Append(",");
def.Append(strY);
def.Append(" Z ");
cCount = 0;
}
else
{
if (cCount == 0) //Curve, in groups of 3
def.Append("C ");
def.Append(strX);
def.Append(",");
def.Append(strY);
def.Append(" ");
cCount += 1;
if (cCount == 3)
cCount = 0;
}
}
}
} def.Append("\"/>");
return def.ToString();
}

相关链接:

​​生成GraphicsPath  ​​

举报

相关推荐

0 条评论