डेविड ब्राउन की परियोजना को इंगित करने के लिए @marapet धन्यवाद। David Brown's Implicit Operator
नमूना अच्छी तरह से काम करता है:
मैं कम से नमूना डाउनलोड किया है।
मैंने अपनी परियोजना में आवश्यक कोड कॉपी किया। मुझे अपना .NET लक्ष्य फ्रेमवर्क 4.0 से 3.5 तक बदलना पड़ा, लेकिन यह कोई समस्या नहीं है।
अभी तक, कोड कभी क्रैश नहीं हुआ है। (भले ही अन्य लोगों के मुद्दों सूचना दी है।)
अद्यतन
डेविड ब्राउन की वेबसाइट नीचे तो मैं कोड मैं वेबसाइट से लिया था के साथ इस जवाब को अद्यतन किया है हो रहा है।
//Code for this Class downloaded from http://implicitoperator.com/blog/2010/4/11/graphviz-c-sample.html
public class GraphViz
{
public const string LIB_GVC = "gvc.dll";
public const string LIB_GRAPH = "graph.dll";
public const int SUCCESS = 0;
/// <summary>
/// Creates a new Graphviz context.
/// </summary>
[DllImport(LIB_GVC)]
public static extern IntPtr gvContext();
/// <summary>
/// Reads a graph from a string.
/// </summary>
[DllImport(LIB_GRAPH)]
public static extern IntPtr agmemread(string data);
/// <summary>
/// Renders a graph in memory.
/// </summary>
[DllImport(LIB_GVC)]
public static extern int gvRenderData(IntPtr gvc, IntPtr g,
string format, out IntPtr result, out int length);
/// <summary>
/// Applies a layout to a graph using the given engine.
/// </summary>
[DllImport(LIB_GVC)]
public static extern int gvLayout(IntPtr gvc, IntPtr g, string engine);
/// <summary>
/// Releases the resources used by a layout.
/// </summary>
[DllImport(LIB_GVC)]
public static extern int gvFreeLayout(IntPtr gvc, IntPtr g);
/// <summary>
/// Releases a context's resources.
/// </summary>
[DllImport(LIB_GVC)]
public static extern int gvFreeContext(IntPtr gvc);
/// <summary>
/// Releases the resources used by a graph.
/// </summary>
[DllImport(LIB_GRAPH)]
public static extern void agclose(IntPtr g);
public static Image RenderImage(string source, string layout, string format)
{
// Create a Graphviz context
IntPtr gvc = gvContext();
if (gvc == IntPtr.Zero)
throw new Exception("Failed to create Graphviz context.");
// Load the DOT data into a graph
IntPtr g = agmemread(source);
if (g == IntPtr.Zero)
throw new Exception("Failed to create graph from source. Check for syntax errors.");
// Apply a layout
if (gvLayout(gvc, g, layout) != SUCCESS)
throw new Exception("Layout failed.");
IntPtr result;
int length;
// Render the graph
if (gvRenderData(gvc, g, format, out result, out length) != SUCCESS)
throw new Exception("Render failed.");
// Create an array to hold the rendered graph
byte[] bytes = new byte[length];
// Copy the image from the IntPtr
Marshal.Copy(result, bytes, 0, length);
// Free up the resources
gvFreeLayout(gvc, g);
agclose(g);
gvFreeContext(gvc);
using (MemoryStream stream = new MemoryStream(bytes))
{
return Image.FromStream(stream);
}
}
}
तो मुझे लगता है कि आप अपने सी # एप्लिकेशन से सिर्फ डॉट यूटिलिटी नहीं चलाना चाहते हैं? – RQDQ
नहीं, यह वही नहीं है जो मैं चाहता हूं। – Rachel