我正在尝试渲染保存(另存为 -> 设备)的 .xml 图表 draw.io。
运行后,我得到了特定的输出:
使用保存的图表作为输入示例:
<mxGraphModel dx="1426" dy="720" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="827" pageHeight="1169" background="#ffffff" math="0" shadow="0">
<root>
<mxCell id="0"/>
<mxCell id="1" parent="0"/>
<mxCell id="2" value="" style="shape=parallelogram;perimeter=parallelogramPerimeter;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="180" y="200" width="120" height="60" as="geometry"/>
</mxCell>
<mxCell id="3" value="" style="whiteSpace=wrap;html=1;aspect=fixed;" vertex="1" parent="1">
<mxGeometry x="360" y="180" width="80" height="80" as="geometry"/>
</mxCell>
<mxCell id="4" value="" style="endArrow=classic;html=1;exitX=0.025;exitY=0.638;exitPerimeter=0;" edge="1" parent="1" source="3" target="2">
<mxGeometry width="50" height="50" relative="1" as="geometry">
<mxPoint x="180" y="430" as="sourcePoint"/>
<mxPoint x="230" y="380" as="targetPoint"/>
</mxGeometry>
</mxCell>
</root>
</mxGraphModel>
然后我需要通过编程将其渲染为PNG格式,因此我编写了C#代码,使用mxgraph库来实现这个目的:
using System;
using System.Drawing;
using com.mxgraph;
namespace MxGraphRendering
{
class Program
{
static void Main(string[] args)
{
var file = mxUtils.ReadFile("../../../export.xml");
var document = mxUtils.ParseXml(file);
var codec = new mxCodec(document);
var graph = new mxGraph();
codec.Decode(document.DocumentElement, graph.Model);
var image = mxCellRenderer.CreateImage(graph, null, 1,
Color.White, false, null);
image.Save("../../../output.png");
Console.ReadKey();
}
}
}
运行后,我得到了特定的输出:
看起来对于这个问题,问题是缺乏期望输出的draw.io样式表。有一种简单的方法可以在我的c# mxGraph实例中全部添加它吗?
或者,另一方面,有没有明确的方法使用draw.io中使用的本机JavaScript从XML渲染PNG?(生成渲染/导出等的函数)
任何帮助都将不胜感激。