• 将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("             //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  

  • 相关阅读:
    机器视觉知识讲的深不如讲的透
    5个免费的3D钣金CAD软件
    39.【C/C++ 全局变量和局部变量 (详解)】
    Redis配置与优化
    使用Redis源码探究字符串的实现
    vue从入门到如土(十万字收藏篇)
    页面结构分析
    FastDFS学习(三)
    RHCE学习 --- 第一次作业
    Maven实战: 从工程创建自定义archetype
  • 原文地址:https://blog.csdn.net/johnsuna/article/details/127964722