0

我正在使用 ASP.NET MVC,使用 Syncfusion 的图表。

我正在尝试在应用程序中添加新的自定义形状。所以我在 draw.io 上创建 SVG 形状。当我在应用程序中导入 SVG 文件时,它会将图像分成多个部分。这就是为什么形状在输出屏幕上变得可怕的原因。

就像我在 Draw.io 中创建以下形状

电感器

现在,当我将图像导入我的项目时,它会分裂形状并在那里给出非常不同的形状。下面的代码我用于导入文件并从 svg 文件中获取路径数据。

[HttpPost]
public ActionResult AddCategoryComponent(HttpPostedFileBase file)
{
   string fileName = Path.GetFileNameWithoutExtension(file.FileName);
   string _tempFileName = Path.GetFileNameWithoutExtension(file.FileName) + "_" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + "" + Path.GetExtension(file.FileName);
   string path = Path.Combine(Server.MapPath("~/Content/Svgfiles"), _tempFileName);
   file.SaveAs(path);

   XDocument document = XDocument.Load(path);
   XElement svg_Element = document.Root;
   var xmlPathList = (from svg_path in svg_Element.Descendants("{http://www.w3.org/2000/svg}path")
                          select svg_path).ToList();

    StringBuilder sb = new StringBuilder();
    int count = 0;

   foreach(var item in xmlPathList)  //Basic shape return single record & complex shape return multiple record. Multiple record changing shape UI
   {
      var itemPath = item.Attributes("d").FirstOrDefault().Value;
      sb.Append(itemPath.ToString());
      count = count + 1;
   }

   var pathResult = sb.ToString();
}

这里 pathResult 返回我传递给 Syncfusion 以创建正确形状的路径。但它显示出非常不同的结果形状作为输出。

那么如何解决这个问题呢?我花了很多时间寻找解决方案,但在任何地方都没有找到任何合适的解决方案。

4

0 回答 0